If cell has data, move down 1 row and paste

Glasgowsmile

Active Member
Joined
Apr 14, 2018
Messages
280
Office Version
  1. 365
Platform
  1. Windows
Good morning,

I have the following macro. I simply want it to look at A1 on the current worksheet, if that cell has data then move down to A2. Then the next time I important data it will look at A2 and paste in A3 etc.

Not quite sure how to do this myself, any help is appreciated!

VBA Code:
Private Sub CommandButton1_Click()
Application.DisplayAlerts = False
Dim crnt As Workbook
Dim source As Workbook

With Application.FileDialog(msoFileDialogOpen)
      .Filters.Clear
      .Filters.Add "CSV Files", "*.csv"
      .AllowMultiSelect = False
      .Show
      If .SelectedItems.Count > 0 Then
         Workbooks.Open .SelectedItems(1)
         Set source = ActiveWorkbook
         
         Sheets("Day").Range("A22").Copy
         Sheet1.Range("A1").PasteSpecial xlPasteValues
      End If
End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Try replacing this
VBA Code:
Sheet1.Range("A1").PasteSpecial xlPasteValues
with
VBA Code:
Sheet1.Range("A"& Rows.Count).end(xlup).offset(1).PasteSpecial xlPasteValues
 
Upvote 0
Try replacing this
VBA Code:
Sheet1.Range("A1").PasteSpecial xlPasteValues
with
VBA Code:
Sheet1.Range("A"& Rows.Count).end(xlup).offset(1).PasteSpecial xlPasteValues

Wow, that's it? I really expected it to be more complicated.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
Follow-up question/problem.

If I wanted to copy multiple cells and paste it across A2, B2, C2 and then move down to A3, B3, C3 etc each time - how can I accomplish that?

I tried to add a transpose thinking that would resolve it but it results in an error.

VBA Code:
Private Sub CommandButton1_Click()
Application.DisplayAlerts = False
Dim crnt As Workbook
Dim source As Workbook

With Application.FileDialog(msoFileDialogOpen)
      .Filters.Clear
      .Filters.Add "Files", "*.xlsx"
      .AllowMultiSelect = False
      .Show
      If .SelectedItems.Count > 0 Then
         Workbooks.Open .SelectedItems(1)
         Set source = ActiveWorkbook
         
         Sheets("Glance").Range("Z10, Z14").Copy
         Sheet1.Range("B", "C" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues, Transpose:=True
      End If
End With
End Sub
 
Upvote 0
How about
VBA Code:
         Sheets("Glance").Range("Z10:Z14").Copy
         Sheet1.Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues, Transpose:=True
 
Upvote 0
Solution
How about
VBA Code:
         Sheets("Glance").Range("Z10:Z14").Copy
         Sheet1.Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues, Transpose:=True
Re-opening this as I'm running into a problem with code.

This code below is not transposing... and I don't understand why
VBA Code:
Sheets("Sheet1").Range("G11, L11, Q11, S11").Copy
         Sheet2.Range("B" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues, Transpose:=True

however, this code which impacts a different sheet is tranposing
VBA Code:
Sheets("Sheet1").Range("Z10, Z14, Z18, Z20").Copy
         Sheet1.Range("C" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues, Transpose:=True
 
Upvote 0
In what way doesn't it work?
 
Upvote 0
That's exactly what it's meant to do, so it's working fine. :)
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,195
Members
452,616
Latest member
intern444

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