index > Visual Basic for Applications (VBA) > Excel: Copying cells under a specific cell containing a title

Excel: Copying cells under a specific cell containing a title


Hi there,

I have a worksheet in Excel containing various data. The data is often on the same form but not at the same position. In this I want to copy a table of data that is located under a cell with the text FX.

I use this code to detect the FX cell.

Sub FoundIt()

Dim mycell As String

Cells.Find(What:="FX", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate

mycell = ActiveCell.Address

It's not neccecarily so that the table is located directly under the cell containing the text FX but at least it is in the same column. So I would need a function that from FX looks in that column after the first numeric value and then copies that plus all that follows in the same column.

Example (should illustrate a normal worksheet)

A B C D
1Test blabla
2

FX

FY
3 disp disp
4 blabla
5

1

2

6

6

5
7

1

8
8

8

9
9

9

5
10

6

4
11
12
13
14 blabla
15

From this I want to copy the numbers under FX i.e. FX = [1 6 1 8 9 6]

Anyone that can help me on this? Note that it isn't neccessarily so that the numbers starts, like in this example 2 rows under FX.

Grateful for help on this

\Jonas




JS
Jonas.S

Jonas this should be no problem... You've done the hard bit

Cells.Find returns a range object and the range object contains quite a few properties like row number and column. You just need a variable for the 'currentRow' and a loop that increments the 'currentRow' one at a time, for each iteration check the value of cell(col, currentRow) and make sure it IsNumeric() or <> "". Continue the loop until IsNumeric(value) = false or value = "" is true.




www.dsmyth.net/blog
Derek Smyth
reply 2

You can use google to search for other answers

 

More Articles

• Expiry dates on Code signing certificates - One Year?
• SetSourcedata of pivotchart on a pivot table that changes
• wrong count of Records in Access.Form
• (Vitual IP Problem ) Web Farming using NLB in windows server 2003...
• Word Macro Runtime Error
• A Simple question about vba editor and vsto
• Help with a formula
• Activate an addin macro, using refferences from local workbook.
• Stupid Question, how to turn Question Mark to Green Check?
• copy chart from excel to word
Welcome to Bokebb   New Update   Joins the collection  
 

New Articles

• Bug or Error ?
• Access "ldb"
• Using visual basic and DDE ( dynamic Dat
• Problem regarding VBA in excel - Combine
• Outlook 2003 VBA - AdvancedSearch in a p
• Subform Problem
• VBA HELP ON WORKSHEET
• Can this be done via an array formula?
• minimize to system tray
• How Can I create an UDF I can use in a c
• Missing files
• Problem with excel, VBA & Bloomberg-
• Find and Replace Carriage Return in Exce
• Calling procedures from a procedure
• Russian programs in Windows XP English v

Hot Articles

• Macros - Excel
• combine 3 combo boxes values into one st
• MultiPage problem!
• Extracting Text from body of Outlook ema
• Creating MROUND function
• Disable editing Excel cells
• For Each Next Loop
• Unable to create FileSystemObject in Acc
• If VB6 support ended, what does that mea
• VBA Queston on Formatting Macro
• Collection Persistence
• Question reg BeforeDoubleClick event in
• VBA code to search and modify in Word
• row height
• unembedding Excel in Internet Explorer

Recommend Articles

• RunTime Error 7 - Out of Memory
• Runtime Error '2001'
• VBA, Access, & SQL Server
• VBA in EXCEL - Connect to SQL Server
• Access and TransferText
• Special action required for one item in
• Output excel file to PDF format
• Word Automation; documents and templates
• Automatic Macros
• ftp using vba
• Emails via Excel
• Issues with Updating Sharepoint List...
• How do I avoid multiple instances of Excel
• need help for VBA code(MS Access)
• Excel Range Selection