CodingExcel VBA Stuff

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  Extrobe (ALDREDD)  
 To:  ALL
30625.1 
I have me some code which inserts a duplication of the selected row, above.
Question 1 -
Using the code below, how do I get it to insert the new row below the selcted row, rather than above?

VBA code:
Private Sub CommandButton1_Click()
    
    Worksheets("Sheet1").Unprotect Password:="#######"

    Dim currentRow As Integer
    Dim currentCol As Integer
    Dim tpnbNew As Integer
    
    'tpnbNew = InputBox("Please enter your new TPNB")
       
    ' where is the cursor
    currentRow = ActiveCell.Row
    currentCol = ActiveCell.Column
    
    ' insert now row above current row
    Rows(currentRow & ":" & currentRow).Select
    Selection.Insert Shift:=xlDown
    
    ' select old row (since currentRow was shifted down one this is now currentRow+1, select to end and copy
    Range("A" & currentRow + 1, "IV" & currentRow + 1).Select
    Selection.Copy
    
    ' select first cell in dest row and paste
    Range("A" & currentRow).Select
    ActiveSheet.Paste
    
    ' restore cursor to correct column in new row
    Cells(currentRow, currentCol).Select
    
    Worksheets("Sheet1").Protect Password:="######"

End Sub

Question 2, how would I tell it to empty selected cells within the new row? The cell column will always be the same, but from the row, there are about 6 cells which need to be copied 'blank'.

Question 3 - is there a way of populating these newly-emptied cells with values from a user form / or pop-up box (you'll see in the code I've created 1 popup box, and have also created a blank form in vba to use)

thanks very much!
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Extrobe (ALDREDD)     
30625.2 In reply to 30625.1 
1) Why can't you do
code:
Rows(currentRow+1 & ":" & currentRow+1).Select
?
0/0
 Reply   Quote More 

 From:  Extrobe (ALDREDD)  
 To:  Peter (BOUGHTONP)     
30625.3 In reply to 30625.2 

that does make sence :/

 

I've also managed to get it to only copy the cells which have a formula in it, and leave the other cells blank.

 

Just need to figure how to get the value of a prompt into the certain cell, but could be tricky, as the code now asks how many news rows a want to insert! :B

0/0
 Reply   Quote More 

 From:  Extrobe (ALDREDD)  
 To:  Peter (BOUGHTONP)     
30625.4 In reply to 30625.2 

do you know haw to make the worksheet not refresh (or prompt to refresh) external links on startup?

 

The sheet only needs refreshing once a week, and only by me, and dont want others being prompted to do so!

 

thanks

0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Extrobe (ALDREDD)     
30625.5 In reply to 30625.4 
I'm afraid I was just making a semi-educated guess - my knowledge of Excel VBA is miniscule. :(
0/0
 Reply   Quote More 

Message 30625.6 was deleted

Message 30625.7 deleted 19 Mar 2007 12:33 by M00RL0CK

 From:  Extrobe (ALDREDD)  
 To:  Mr (M00RL0CK)     
30625.8 In reply to 30625.7 
Another one for you, if I may? I've got a spreadsheet which pulls data from another workbook. What my boss wants is a few line below the report, to see an extract of the same report, but just 5 lines of it, being the top 5 results of a sort. I know that makes no sense at all, so I've attached an example of how it might look (I've pasted values on it). At the top is the main report - could be anywhere from 20 - 2000 lines - and mornally about 65 columns. this will always be sorted by Column L in this example. Below all of this are two extracts, one showing the highest cover lines, the other showing the lowest. This report is updated weekly, and the extract needs to reflect this. Can you think of any way of doing this? I've tried creating a Macro to do it, which mmics me copying into a new sheet, sorting & copying back, but this just doesn't give me the flexability I need. Is this even possable? Thanks!

Attachments:
test.xls

0/0
 Reply   Quote More 

Message 30625.9 was deleted

Reply to All    
 

1–9

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2024 Project Beehive Forum

Forum Stats