IsEmpty(destination.Range

Rubber Beaked Woodpecker

Board Regular
Joined
Aug 30, 2015
Messages
203
Office Version
  1. 2021
The following code works very well. However if I change If IsEmpty(destination.Range("X5")) Then to If IsEmpty(destination.Range("AA5")) Then the macro pastes in column A1.

What am I doing wrong please as I would like the macro to paste in column AA the first time it is run.
TIA
VBA Code:
Sub logBalance()
  
Dim source As Worksheet
Dim destination As Worksheet
Dim emptyColumn As Long

Set source = Sheets("Sheet1")
Set destination = Sheets("Sheet1")

source.Range("o5:o16").Copy

emptyColumn = destination.Cells(5, destination.Columns.Count).End(xlToLeft).Column

If IsEmpty(destination.Range("X5")) Then
    destination.Cells(1, 1).PasteSpecial Transpose:=True
    Range("S1").Select
    Application.CutCopyMode = False
  
Else
    emptyColumn = emptyColumn + 1
    destination.Cells(5, emptyColumn).PasteSpecial Transpose:=False
    Application.CutCopyMode = False
   
End If

  
End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
VBA Code:
If IsEmpty(destination.Range("X5")) Then
    destination.Cells(1, 1).PasteSpecial Transpose:=True
    Range("S1").Select
    Application.CutCopyMode = False

with the above from your code if you simply change "X5" to "AA5" the only thing that will change is the cell that it will check is empty.
In order to change the paste location you need to change the
VBA Code:
    destination.Cells(1, 1).PasteSpecial Transpose:=True
cells(1,1) refers to row1 column1 or "A1". so you will need to change it to where ever you want the paste to occur
 
Upvote 0

Forum statistics

Threads
1,214,639
Messages
6,120,679
Members
448,977
Latest member
dbonilla0331

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