Using a variable to select a range excluding one cell.

VBABeginer_Chappers

New Member
Joined
Mar 8, 2018
Messages
10
Hi

I have been trying to write some code which checks if a cell is empty, if the cell is empty it moves the data from that row and the next 2 columns down a row. The problem I have is that the second column contains the address of a linked cell, hence I need to check if the address is still correct and change it if required.

e.g

STU
2Inbox
3Jump From2
4Copy To
5Jump$S$22
6Outbox
7Jump$S$93
8Add$C$4
9Jump From3
10

<tbody>
</tbody>

On the example above If I was to check cell S4, it would move Range S4:S9 down a row, The reference "$S$9" in Cell T7 would need to change to $S$10 however the reference "$S$2" at T5 would not, The number in column U is to pair the Jump with a Jump From.

Code:
Sub CheckIfEmpty()


Dim j, h As Integer
Dim JumpNumber As Integer
Dim JumpNumberLcn As String


If Not IsEmpty(ActiveCell.Value) Then


Selection.Insert Shift:=xlDown
Selection.Offset(0, 1).Insert Shift:=xlDown
Selection.Offset(0, 2).Insert Shift:=xlDown
Selection.Offset(0, -1).Insert Shift:=xlDown


For i = x To 1000


j = i + 1
h = i - 1


    If Range("S" & i).Value = "Jump" Then
    JumpNumber = Range("U" & i)
    JumpNumberLcn = Range(.Range("U2:U" & h), .Range("U" & j:"U1000")).Find(JumpNumber)
    Range("T" & i).Value = JumpNumberLcn
            
    Else
          
    End If
    
Next i


Else


Exit Sub


End If


End Sub

Line

"JumpNumberLcn = Range(.Range("U2:U" & h), .Range("U" & j:"U1000")).Find(JumpNumber)"

doesn't Work

Many Thanks
 

Some videos you may like

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,219
Office Version
  1. 365
Platform
  1. Windows
Which column are you checking for empty cells?
 

VBABeginer_Chappers

New Member
Joined
Mar 8, 2018
Messages
10
Hi Apologies I'm checking Column S. The sub is part of a much bigger program which works down column S, and calls this sub.
 

VBABeginer_Chappers

New Member
Joined
Mar 8, 2018
Messages
10
The main thing I am struggling with is I want to select range A1:A1000 but not row "i" where i is the variable that changes in my loop
 

Watch MrExcel Video

Forum statistics

Threads
1,122,893
Messages
5,598,712
Members
414,254
Latest member
MarieCo

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
Top