i'm new to this and i am hoping someone can help.
im trying to re-vamp database managment procedures at work and have got stuck trying to use some functions of visual basic.
i am trying to move an entire row from a database on 'sheet 1' to the first empty row on 'sheet 2' dependant on column 'B' of 'sheet 1' containing an 'N'.
this may sound simple enough, but i have spent the last day and a half researching on the net, ironically greatly reducing my current poductivity, and getting nowhere.
macros thati have tried will move a row but each subsequent row will overwrite each previously moved row. agghhh.
any help will be greatly appreciated.
Given the lack of details and a sample workbook, perhaps this can be a start for you.
See attached.Option Explicit Sub MoveRows() Dim lastrow As Long lastrow = Sheet2.Cells(Rows.Count, 1).End(xlUp).Row + 1 Application.ScreenUpdating = False With Sheet1 .Range("A1").CurrentRegion.AutoFilter Field:=2, Criteria1:="=N", Operator:=xlAnd .Range("a1").CurrentRegion.Offset(1, 0).SpecialCells(xlCellTypeVisible).Copy Sheet2.Range("A" & lastrow) .Range("A1").CurrentRegion.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete .AutoFilterMode = False End With Application.CutCopyMode = False Application.ScreenUpdating = True End Sub
Palmetto
Do you know . . . ?
You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.
thanks for the input will give it a shot.
have just tried it and having the following problems:
macro will not run without being asked to from VBA interface
initially only sends rows 1-5 to sheet 2 (regardless of what row is given condition N in column 2)
subsequent transfer attempts only overlay on top of previous data
might just be being stupid somwhere but would be extremely greatful for any more advice.
cheers
The code I gave is just a basic approach based on the description in your thread and is, therefore, not tailored to your specific workbook and would have to be modified.
It would be best if you uploaded a sample workbook that both duplicates the exact structure of your real workbook and contains some data (non-sensitive). We could then tailore the code to the exact needs of your workbook.
Palmetto
Do you know . . . ?
You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.
here is the attached workbook example, hope this works.
thanking you in advance.
ammended![]()
Last edited by mjsmith127; 04-21-2010 at 12:03 PM.
Please re-upload a new worbook that contains representative data so we can get the right solution and eliminate questions. You can edit your previous post to remove the attachement and then upload the new workbook in the same post then reply to this post to let us know.
Palmetto
Do you know . . . ?
You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.
i have ammended that as you asked.
See attached.Option Explicit Sub Move_N_Rows() Dim lrowSh1 As Long, lcolSh1 As Long, lrowSh2 As Long lrowSh1 = Sheet1.Cells(Rows.Count, 2).End(xlUp).Row lrowSh2 = Sheet2.Cells(Rows.Count, 2).End(xlUp).Row + 1 lcolSh1 = Sheet1.Cells(6, Columns.Count).End(xlToLeft).Column If lrowSh2 < 3 Then lrowSh2 = 3 'account for header row Application.ScreenUpdating = False With Sheet1 If .AutoFilterMode = True Then .AutoFilterMode = False .Range("B6", Cells(lrowSh1, lcolSh1)).AutoFilter field:=1, Criteria1:="=N", Operator:=xlAnd .Range("B6", Cells(lrowSh1 - 1, lcolSh1)).Offset(1, 0).SpecialCells(xlCellTypeVisible).Copy Sheet2.Range("B" & lrowSh2) .Range("B6", Cells(lrowSh1 - 1, lcolSh1)).Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete .AutoFilterMode = False End With Application.ScreenUpdating = True End Sub
Palmetto
Do you know . . . ?
You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.
thanks for that, your a gentleman.
Help!!!!
I've made some minor adjustments to my workbook and keep losing imformation.
If anyone can puzzle out my Visual Basic coding I would be most greatful.
Cheers.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks