VBA - making an exception for certain cells

B

badboybmw_886

Hello there,

I have a piece of VBA code that I have been using in a mock up excel
system for my A levels

the code places the cell number + and offset of 113 into the cell you
click on in coloumb B. Sort of working like an auto number in the next
cell. But i dont want it to do this for rows 1 -5 is there anyway of
doing this?

Heres the code;

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Dim RowOffset As Long
Dim IndexCol As String

RowOffset = 113

IndexCol = "B"

Intersect(ActiveCell.EntireRow, Columns(IndexCol)).Value =
ActiveCell.Row + RowOffset
End Sub

Any help would be greatly appreciated
 
H

Homey

try this-

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Cell As Range
For Each Cell In Target
If Cell.Row > 5 Then
Cells(Cell.Row, "B").Value = Cell.Row + 113
End If
Next
End Sub

| Hello there,
|
| I have a piece of VBA code that I have been using in a mock up excel
| system for my A levels
|
| the code places the cell number + and offset of 113 into the cell you
| click on in coloumb B. Sort of working like an auto number in the next
| cell. But i dont want it to do this for rows 1 -5 is there anyway of
| doing this?
|
| Heres the code;
|
| Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
| Dim RowOffset As Long
| Dim IndexCol As String
|
| RowOffset = 113
|
| IndexCol = "B"
|
| Intersect(ActiveCell.EntireRow, Columns(IndexCol)).Value =
| ActiveCell.Row + RowOffset
| End Sub
|
| Any help would be greatly appreciated
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top