Macro select blank cells (with formula)

misiek5510

New Member
Joined
May 25, 2021
Messages
38
Office Version
  1. 2016
Platform
  1. Windows
  2. Mobile
HI all,

I have the following macro which works, however is selecting blank cells which is causing problems. The cells are blank however are containing formulas, but since I'm coping them as values only it shouldn't matter?
When I paste it on the sheet "Data" it Pastes with the blank cells, and next time I use this macro it pastes AFTER the blank cells instead of right after the last row with data.

Sub add()

Range("B5").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets("Data").Select
Range("Data[[#Headers],[Site]]").Select
Selection.End(xlDown).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=True, Transpose:=False
End Sub
 
Hi Jason,

It worked partially. It basically copied some data (not the correct range), and pasted it on the wrong column, and every time I run the macro it pastes in the same place as opposed to pasting under previous last row.
 
Upvote 0

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Slight typo in Jason's code, try
VBA Code:
Sub add()
Dim rFound As Range, rng As Range
Set rFound = ActiveSheet.Cells.Find("?*", Range("A1"), xlValues, xlWhole, xlByRows, xlPrevious, False, False, False)
Set rng = Range("B5", rFound)
Sheets("Data").Range("Data[[#Headers],[Site]]").End(xlDown).Offset(1).Resize(rng.Rows.Count, rng.Columns.Count).Value = rng.Value
End Sub
 
Upvote 0
Yes. Now it almost works. It pastes the data in the right fields and it does paste after the last row with data, however it seems to be coping too many columns (10 and I only use 4). I always need the range B5:E24 to be copied.
 
Upvote 0
Your original attempt used xlToRight to get the last column, there was no indication that there might be anything beyond the range to copy. As with most questions, it is better if you tell us what you are trying to do clearly rather than simply telling us what you've tried doing and assuming that we can figure it out from that.

VBA Code:
Sub add()
Dim rFound As Range, rng As Range
Set rFound = ActiveSheet.Range("E:E").Find("?*", Range("E1"), xlValues, xlWhole, xlByRows, xlPrevious, False, False, False)
Set rng = Range("B5", rFound)
Sheets("Data").Range("Data[[#Headers],[Site]]").End(xlDown).Offset(1).Resize(rng.Rows.Count, rng.Columns.Count).Value = rng.Value
End Sub
 
Upvote 0
Solution
Your original attempt used xlToRight to get the last column, there was no indication that there might be anything beyond the range to copy. As with most questions, it is better if you tell us what you are trying to do clearly rather than simply telling us what you've tried doing and assuming that we can figure it out from that.

VBA Code:
Sub add()
Dim rFound As Range, rng As Range
Set rFound = ActiveSheet.Range("E:E").Find("?*", Range("E1"), xlValues, xlWhole, xlByRows, xlPrevious, False, False, False)
Set rng = Range("B5", rFound)
Sheets("Data").Range("Data[[#Headers],[Site]]").End(xlDown).Offset(1).Resize(rng.Rows.Count, rng.Columns.Count).Value = rng.Value
End Sub
That worked great :) Thank you both. Apologies, I specified my range in the 2nd reply, however next time I'll try to be more precise :)
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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