Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 6
Default Using VBA to find a value and select a range

I am trying to write a macro that will let me find a specific vale in a
specific column, then select part of the row that the value is in, beginnign
with a column 31 cells away from the column that the specific value is in.
Someone suggested to me that I use an IF statement, but this is all I know
about that:

IF [value in column B] is €śGrand Total€ť Then select from column AF to the
end of the array in that row and copy it and paste a transpose of the values
starting in cell I9 of worksheet X.

What is the best way for me to accomplish this goal?
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,934
Default Using VBA to find a value and select a range

Does this macro do what you want?

Sub FindGrandTotal()
Dim StartDataColumn As Long, LastDataColumn As Long
StartDataColumn = 31
LastDataColumn = Cells.Find(What:="*", SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Column
Columns("B").Find("Grand Total", LookAt:=xlWhole, MatchCase:=False). _
Offset(0, StartDataColumn - 1).Resize(1, _
LastDataColumn - StartDataColumn).Select
End Sub

--
Rick (MVP - Excel)



"AlexJarvis" wrote in message
...
I am trying to write a macro that will let me find a specific vale in a
specific column, then select part of the row that the value is in,
beginnign
with a column 31 cells away from the column that the specific value is in.
Someone suggested to me that I use an IF statement, but this is all I know
about that:

IF [value in column B] is €śGrand Total€ť Then select from column AF to the
end of the array in that row and copy it and paste a transpose of the
values
starting in cell I9 of worksheet X.

What is the best way for me to accomplish this goal?


  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,533
Default Using VBA to find a value and select a range

Hi

Try this:

Sub test()
Dim fFound As Range
Dim f As Variant
Dim SearchRng As Range
Dim DestRng As Range

Set DestRng = Worksheets("Sheet X").Range("I9") ' Change Sheet name
Set SearchRng = Range("B1", Range("B" & Rows.Count).End(xlUp))
Set f = Cells.Find(What:="Grand Total", after:=Range("B1"), _
LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If f Is Nothing Then Exit Sub 'No match found

Set fFound = f
Do
fRow = f.Row
Range("AF" & fRow, Range("AF" & fRow).End(xlToRight)).Copy
DestRng.PasteSpecial xlPasteAll, Transpose:=True
Set DestRng = DestRng.Offset(0, 1) ' next match is pasted in J9
SearchRng.FindNext , after:=f
Loop Until f.Address = fFound.Address
End Sub

Regards,
Per

"AlexJarvis" skrev i meddelelsen
...
I am trying to write a macro that will let me find a specific vale in a
specific column, then select part of the row that the value is in,
beginnign
with a column 31 cells away from the column that the specific value is in.
Someone suggested to me that I use an IF statement, but this is all I know
about that:

IF [value in column B] is €śGrand Total€ť Then select from column AF to the
end of the array in that row and copy it and paste a transpose of the
values
starting in cell I9 of worksheet X.

What is the best way for me to accomplish this goal?


  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,934
Default Using VBA to find a value and select a range

Sorry, I misread your question. Give this macro a try instead...

Sub FindGrandTotal()
Dim GrandTotal As Range, DataSheet As Worksheet, CopySheet As Worksheet
Set DataSheet = Worksheets("Sheet3")
Set CopySheet = Worksheets("X")
Set GrandTotal = DataSheet.Columns("B").Find("Grand Total", _
LookAt:=xlWhole, MatchCase:=False)
If Not GrandTotal Is Nothing Then
CopySheet.Range("I9").Resize(Columns.Count - 31) = WorksheetFunction. _
Transpose(Range(GrandTotal.Offset(0, 30), DataSheet.Cells( _
GrandTotal.Row, Columns.Count)))
End If
End Sub

--
Rick (MVP - Excel)



"Rick Rothstein" wrote in message
...
Does this macro do what you want?

Sub FindGrandTotal()
Dim StartDataColumn As Long, LastDataColumn As Long
StartDataColumn = 31
LastDataColumn = Cells.Find(What:="*", SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Column
Columns("B").Find("Grand Total", LookAt:=xlWhole, MatchCase:=False). _
Offset(0, StartDataColumn - 1).Resize(1, _
LastDataColumn - StartDataColumn).Select
End Sub

--
Rick (MVP - Excel)



"AlexJarvis" wrote in message
...
I am trying to write a macro that will let me find a specific vale in a
specific column, then select part of the row that the value is in,
beginnign
with a column 31 cells away from the column that the specific value is
in.
Someone suggested to me that I use an IF statement, but this is all I
know
about that:

IF [value in column B] is €śGrand Total€ť Then select from column AF to
the
end of the array in that row and copy it and paste a transpose of the
values
starting in cell I9 of worksheet X.

What is the best way for me to accomplish this goal?


  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 6
Default Using VBA to find a value and select a range

This one is right on the money. Thank you!

-A

"Rick Rothstein" wrote:

Sorry, I misread your question. Give this macro a try instead...

Sub FindGrandTotal()
Dim GrandTotal As Range, DataSheet As Worksheet, CopySheet As Worksheet
Set DataSheet = Worksheets("Sheet3")
Set CopySheet = Worksheets("X")
Set GrandTotal = DataSheet.Columns("B").Find("Grand Total", _
LookAt:=xlWhole, MatchCase:=False)
If Not GrandTotal Is Nothing Then
CopySheet.Range("I9").Resize(Columns.Count - 31) = WorksheetFunction. _
Transpose(Range(GrandTotal.Offset(0, 30), DataSheet.Cells( _
GrandTotal.Row, Columns.Count)))
End If
End Sub

--
Rick (MVP - Excel)



"Rick Rothstein" wrote in message
...
Does this macro do what you want?

Sub FindGrandTotal()
Dim StartDataColumn As Long, LastDataColumn As Long
StartDataColumn = 31
LastDataColumn = Cells.Find(What:="*", SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Column
Columns("B").Find("Grand Total", LookAt:=xlWhole, MatchCase:=False). _
Offset(0, StartDataColumn - 1).Resize(1, _
LastDataColumn - StartDataColumn).Select
End Sub

--
Rick (MVP - Excel)



"AlexJarvis" wrote in message
...
I am trying to write a macro that will let me find a specific vale in a
specific column, then select part of the row that the value is in,
beginnign
with a column 31 cells away from the column that the specific value is
in.
Someone suggested to me that I use an IF statement, but this is all I
know
about that:

IF [value in column B] is €śGrand Total€ť Then select from column AF to
the
end of the array in that row and copy it and paste a transpose of the
values
starting in cell I9 of worksheet X.

What is the best way for me to accomplish this goal?


.

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 can change range to select active rows instead of :=Range("S10 ldiaz Excel Discussion (Misc queries) 7 August 29th 08 03:52 PM
find & select Aaron Hodson \(Coversure\) Excel Worksheet Functions 2 August 21st 08 08:36 AM
When entering data into a range of cells, select the entire range. Q Excel Discussion (Misc queries) 0 September 26th 07 04:36 AM
select date range then find average of values in another cell rob117 Excel Worksheet Functions 3 May 3rd 07 03:34 PM
How to Select a relative range with Using "Find" and Offset() Dennis Excel Discussion (Misc queries) 7 July 27th 05 03:57 PM


All times are GMT +1. The time now is 12:51 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"