Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Find a Specific Column

I have source code in place to find the lastcolumn, how do I decrement 3 or 4
columns... for example lastcolumn = "$H$4" I want to specify a range of
"$E$4:$h$4" I am basically adding 3 columns and later on will like to select
the range of columns just added to do additional programming on. Below is
how I set my lastcol variable

For Each cell In Range(Range("A4"), Range("IV4"))
LastCol = cell.Address

If cell = Empty Then
Exit Sub
End If
Next cell


Any help is greatly appreciated
ToniS

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Find a Specific Column


cell.offset(0,-3).resize(1,4)

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"ToniS" wrote in message
...
I have source code in place to find the lastcolumn, how do I decrement 3 or
4
columns... for example lastcolumn = "$H$4" I want to specify a range of
"$E$4:$h$4" I am basically adding 3 columns and later on will like to
select
the range of columns just added to do additional programming on. Below is
how I set my lastcol variable

For Each cell In Range(Range("A4"), Range("IV4"))
LastCol = cell.Address

If cell = Empty Then
Exit Sub
End If
Next cell


Any help is greatly appreciated
ToniS



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Find a Specific Column

On Aug 6, 3:44 pm, ToniS wrote:
I have source code in place to find the lastcolumn, how do I decrement 3 or 4
columns... for example lastcolumn = "$H$4" I want to specify a range of
"$E$4:$h$4" I am basically adding 3 columns and later on will like to select
the range of columns just added to do additional programming on. Below is
how I set my lastcol variable

For Each cell In Range(Range("A4"), Range("IV4"))
LastCol = cell.Address

If cell = Empty Then
Exit Sub
End If
Next cell

Any help is greatly appreciated
ToniS


You could do something like the following:

Dim r1 As Range, r2 As Range

Set r1 = Range("d1") 'your last column
Set r2 = Range(r1.Offset(0, -3), r1)

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Find a Specific Column

Dim rng as Range
set rng = Range("IV4").End(xltoLeft).Offset(0,-3).Resize(1,4)

demo'd from the immediate window


set rng = Range("IV4").End(xltoLeft).Offset(0,-3).Resize(1,4)
? rng.Address
$E$4:$H$4

--
Regards,
Tom Ogilvy


"ToniS" wrote:

I have source code in place to find the lastcolumn, how do I decrement 3 or 4
columns... for example lastcolumn = "$H$4" I want to specify a range of
"$E$4:$h$4" I am basically adding 3 columns and later on will like to select
the range of columns just added to do additional programming on. Below is
how I set my lastcol variable

For Each cell In Range(Range("A4"), Range("IV4"))
LastCol = cell.Address

If cell = Empty Then
Exit Sub
End If
Next cell


Any help is greatly appreciated
ToniS

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Find a Specific Column

Thanks for everyone's input, I really appreciate it!! I am now getting the
right range, but the replace the formula to actual value is not working for
me. Below is what I have.

Dim tmpRange As Range
Dim ReplaceFormulaRange As Range
Dim rng As Range

Set ReplaceFormulaRange = Range("IV4").End(xlToLeft).Offset(0,
-2).Resize(1, 3)

MsgBox ("replaceformrng= " & ReplaceFormulaRange.Address)


Set tmpRange = Range("sheet2!a2:d2100")
ReplaceFormulaRange.Copy
ReplaceFormulaRange.PasteSpecial Paste:=xlPasteValues,
Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

tmpRange.EntireColumn.Delete

The cells formula gets set to =VLOOKUP($A$5,Sheet2!#REF!,2,FALSE)
If I hardcode the below range I get the correct results, the value from the
temp table on sheet2

' works
' Set ReplaceFormulaRange = Range("sheet1!F5:H09") ' need to change
to a variable
'
' Set tmpRange = Range("sheet2!a2:d2100")
' ReplaceFormulaRange.Copy
' ReplaceFormulaRange.PasteSpecial Paste:=xlPasteValues,
Operation:=xlNone, SkipBlanks _
' :=False, Transpose:=False
'
' tmpRange.EntireColumn.Delete


"Tom Ogilvy" wrote:

Dim rng as Range
set rng = Range("IV4").End(xltoLeft).Offset(0,-3).Resize(1,4)

demo'd from the immediate window


set rng = Range("IV4").End(xltoLeft).Offset(0,-3).Resize(1,4)
? rng.Address
$E$4:$H$4

--
Regards,
Tom Ogilvy


"ToniS" wrote:

I have source code in place to find the lastcolumn, how do I decrement 3 or 4
columns... for example lastcolumn = "$H$4" I want to specify a range of
"$E$4:$h$4" I am basically adding 3 columns and later on will like to select
the range of columns just added to do additional programming on. Below is
how I set my lastcol variable

For Each cell In Range(Range("A4"), Range("IV4"))
LastCol = cell.Address

If cell = Empty Then
Exit Sub
End If
Next cell


Any help is greatly appreciated
ToniS

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i find the last specific value in a column? bradsmith37 Excel Discussion (Misc queries) 9 June 23rd 20 05:22 PM
Find specific column and copy row. Kevin Porter Excel Programming 2 February 22nd 07 11:17 PM
Find specific column titles and copy the column to new workboo JLGWhiz Excel Programming 0 December 11th 06 11:23 PM
Find specific column titles and copy the column to new workboo JLGWhiz Excel Programming 0 December 11th 06 11:09 PM
find a specific value in a column and write another column MUSTANG Excel Discussion (Misc queries) 2 February 5th 06 09:24 AM


All times are GMT +1. The time now is 11:50 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"