I don't know what to do to correct this vba code

Status
Not open for further replies.

daniboymu

Board Regular
Joined
Nov 1, 2020
Messages
54
Office Version
  1. 2019
Platform
  1. Windows
my problem here is i dont know what i have to change on the vba code so I can get the information from ROW 5 and store at database, i uploaded two images showing what happens when i run the macro, I will be very grateful if someone could help me.

VBA Code:
Sub paste()
' paste2 Macro
    Dim lastRow As Long
' this finds the number of the last row
    Rows(7) = Cells(Rows.Count, 5).End(xlUp).Row
    Range("A5:DG5").Copy
    Cells(lastRow + 1, 1).PasteSpecial paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        Rows("7:7").Select
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
End Sub
 

Attachments

  • after clicked.png
    after clicked.png
    114.7 KB · Views: 10
  • before clicking.png
    before clicking.png
    122.2 KB · Views: 9

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
hi Dave,, I need the information copied should be paste on the 7 ROW and not on the last row which is like 1200 rows down
the macro works like: it gets the information from ROW 5 which is RTD and copies and past on the ROW 7 to add to database, but when i click to update, the macro messes up everything at ROWS 1,2 AND 3 and then when the copied stuff is paste to ROW 7 MESS UP THE DATABASE, you can check that on the 2 prints that i uploaded
 
Upvote 0
my problem here is i dont know what i have to change on the vba code so I can get the information from ROW 5 and store at database, i uploaded two images showing what happens when i run the macro, I will be very grateful if someone could help me.

VBA Code:
Sub paste()
' paste2 Macro
    Dim lastRow As Long
' this finds the number of the last row
    Rows(7) = Cells(Rows.Count, 5).End(xlUp).Row
    Range("A5:DG5").Copy
    Cells(lastRow + 1, 1).PasteSpecial paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        Rows("7:7").Select
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
End Sub
Will row 7 always be empty for a row to be pasted?
 
Upvote 0
the macro works like: it gets the information from ROW 5 which is RTD and copies and past on the ROW 7 to add to database, but when i click to update, the macro messes up everything at ROWS 1,2 AND 3 and then when the copied stuff is paste to ROW 7 MESS UP THE DATABASE, you can check that on the 2 prints that i uploaded
Hello dani please correct me if i am wrong-
your requirement is:
1. copy the entire row 5 from range a5:dg5
2. shift the row 8 data to row 9
3. paste the copied data of row 5 to row 8, (inserting a new row )

is this your requirement
?
 
Upvote 0
Will row 7 always be empty for a row to be pasted?
yes the macro paste the information at ROW 7 and at the same time it creates a new ROW which becomes ROW 7 again and the Row with the paste information turns into ROW 8
 
Upvote 0
How about
VBA Code:
Sub daniboy()
   Rows(7).Insert
   Range("A8:DG8").Value = Range("A5:DG5").Value
End Sub
 
Upvote 0
Hello dani please correct me if i am wrong-
your requirement is:
1. copy the entire row 5 from range a5:dg5
2. shift the row 8 data to row 9
3. paste the copied data of row 5 to row 8, (inserting a new row )

is this your requirement
?
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,214,911
Messages
6,122,199
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top