Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Collect value

I have 4 cells: H8 I8 J8 K8
If change H8, I8 J8 K8 cells have variable value.
I want to change values of H8 from 10 to 150 and collect all 4 cells value
in columns AF AG AH AI.

Please help me with same VBA code. Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,203
Default Collect value

This routine will do the data entry for you and capture the results. To put
the code into your workbook, open it and press [Alt]+[F11] to open the VB
Editor. Use Insert -- Module in it to open a new code module, then copy and
paste the code into it. Select the proper worksheet and then run the Macro.

Sub FillAndCapture()
Dim homeCell As Range
Dim baseCell As Range
Dim LC As Integer
Dim MLC As Integer

Set homeCell = Range("H8")
For LC = 10 To 150
homeCell = LC
Set baseCell = Range("AF" & Rows.Count). _
End(xlUp).Offset(1, 0)
For MLC = 0 To 3
baseCell.Offset(0, MLC) = _
homeCell.Offset(0, MLC)
Next
Next
Set baseCell = Nothing
Set homeCell = Nothing
End Sub


Now, if you want to simply capture what you type into H8 when it changes,
then use the following worksheet code (don't use the code above). To put
this to use, open the workbook, select the appropriate sheet and then
right-click on its name tab and choose [View Code] from the list and copy the
code and paste it into the code module. Any time you type an entry into H8,
it's contents and those of I8, J8 and K8 will be captured into a new row at
AF, AG, AH and AI.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim baseCell As Range
Dim LC As Integer

If Target.Address < "$H$8" Then
Exit Sub
End If
'change was made in H8
'prevent reentry while we're
'doing the work
Application.EnableEvents = False
'set up a reference to the next
'available cell in column AF on the sheet
Set baseCell = Range("AF" & Rows.Count). _
End(xlUp).Offset(1, 0)
For LC = 0 To 3
baseCell.Offset(0, LC) = _
Target.Offset(0, LC)
Next
Set baseCell = Nothing
Application.EnableEvents = True
End Sub


"cferoiu" wrote:

I have 4 cells: H8 I8 J8 K8
If change H8, I8 J8 K8 cells have variable value.
I want to change values of H8 from 10 to 150 and collect all 4 cells value
in columns AF AG AH AI.

Please help me with same VBA code. Thanks.

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
Collect value cferoiu Excel Programming 3 March 27th 10 03:46 AM
A little VBA help please: collect row value not column Preschool Mike Excel Worksheet Functions 5 September 9th 09 03:30 PM
Collect Modules into one workbook Pops Jackson Excel Programming 2 December 16th 08 02:30 AM
Collect numbers.... Zadig Galbaras Excel Discussion (Misc queries) 5 September 25th 05 02:20 AM
collect data from different worksheet sheva Excel Worksheet Functions 0 August 16th 05 03:22 PM


All times are GMT +1. The time now is 04:46 PM.

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

About Us

"It's about Microsoft Excel"