Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default automatically fill in a cell if the adjacent cell has any value

This should be a simple question for you programmers out there.
I have more than 100 spreadsheats all with the same structure so if I can
write a macro it will save me lots of repetitive action.
I need to fill in a column with the value which is always contained in cell
A1. If there are values in column B then fill in adjacent cell in column A
with the value named in cell A1.
In other words, if cell A1 ="Detroit" and there are some/any values in
column B, then fill in the cells in column A as "Detroit". Some spreadsheats
have 5 rows to be filled in and some have 100 rows to be filled in.

I have tried several different times using a book I bought at Barnes &
Nobles, but I am having a hard time implementing a solution.

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default automatically fill in a cell if the adjacent cell has any value

Hi!

I hope, have understood you right, so try this:

Create a modul and copy the code below in this modul, then start the macro:

Sub FillIn()
For SheetCount = 1 To Worksheets.Count
Worksheets(SheetCount).Activate
Cells(1).Select
Selection.CurrentRegion.Select
LastRow = Selection.Rows.Count
For RowCount = 1 To LastRow
If Cells(RowCount, 2).Value < "" Then
Cells(RowCount, 1).Value = Cells(1, 1).Value
End If
Next RowCount
Next SheetCount
End Sub


"Geographer" wrote:

This should be a simple question for you programmers out there.
I have more than 100 spreadsheats all with the same structure so if I can
write a macro it will save me lots of repetitive action.
I need to fill in a column with the value which is always contained in cell
A1. If there are values in column B then fill in adjacent cell in column A
with the value named in cell A1.
In other words, if cell A1 ="Detroit" and there are some/any values in
column B, then fill in the cells in column A as "Detroit". Some spreadsheats
have 5 rows to be filled in and some have 100 rows to be filled in.

I have tried several different times using a book I bought at Barnes &
Nobles, but I am having a hard time implementing a solution.

Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default automatically fill in a cell if the adjacent cell has any value


Try:



Sub CopyA1()
Set rng = Range("b1:b" & [b65536].End(xlUp).Row)
For Each c In rng
If Not IsEmpty(c) Then
c.Offset(0, -1).Value = Range("A1").Value
End If
Next
End Sub


To run through all your (100??) spreadsheets use:
Sub CopyA1Plus()
Application.ScreenUpdating=False
Set AcSheet = ActiveSheet
For Each sh In Worksheets
sh.Activate
Set rng = Range("b1:b" & [b65536].End(xlUp).Row)
For Each c In rng
If Not IsEmpty(c) Then
c.Offset(0, -1).Value = Range("A1").Value
End If
Next
Next
AcSheet.Select
Application.ScreenUpdating=True
End Su

--
david
-----------------------------------------------------------------------
davidm's Profile: http://www.excelforum.com/member.php...fo&userid=2064
View this thread: http://www.excelforum.com/showthread.php?threadid=37561

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default automatically fill in a cell if the adjacent cell has any value

Dim sh as Worksheet, rng as Range, cell as Range
for each sh in ActiveWorkbook.Worksheets
set rng = sh.Range(sh.Cells(1,2),sh.Cells(rows.count,2).End( xlup))
for each cell in rng
if not isempty(cell) then
cell.offset(0,-1).Value = sh.Range("A1").Value
end if
next
Next

--
Regards,
Tom Ogilvy


"Geographer" wrote in message
...
This should be a simple question for you programmers out there.
I have more than 100 spreadsheats all with the same structure so if I can
write a macro it will save me lots of repetitive action.
I need to fill in a column with the value which is always contained in

cell
A1. If there are values in column B then fill in adjacent cell in column A
with the value named in cell A1.
In other words, if cell A1 ="Detroit" and there are some/any values in
column B, then fill in the cells in column A as "Detroit". Some

spreadsheats
have 5 rows to be filled in and some have 100 rows to be filled in.

I have tried several different times using a book I bought at Barnes &
Nobles, but I am having a hard time implementing a solution.

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
fill in date into adjacent cell automatically FS Excel Discussion (Misc queries) 2 March 25th 10 09:27 PM
Validation List to fill adjacent cell with IF? braeden13 Excel Discussion (Misc queries) 2 March 14th 08 02:54 AM
Fill cells if adjacent cell match criteria Jess Excel Discussion (Misc queries) 6 June 1st 06 09:18 PM
Auto-fill cell based on adjacent cell information.. sans Excel Worksheet Functions 1 October 17th 05 11:38 PM
How to Automatically Move Cell datato adjacent cell.. cardingtr Excel Discussion (Misc queries) 1 October 17th 05 03:59 AM


All times are GMT +1. The time now is 05:51 AM.

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"