Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I am seaching through a column of data and when I find a cell that has
matching data I want to insert data into other columns in the same row. Also How do I define a blank cell in my search? I don't want any insertions past the last row of data as I'm thinking if I have the "blank" cell case it will keep on inserting data into the other columns for ever. Code: -------------------- Columns("B:B").Select For Each C In Selection Select Case UCase(C) Case "115297": then insert into A "22" and insert into I "23" Case "276534": then insert into A "27" and insert into I "93" Case "blank?": then insert into A "999" and insert into I "999" End Select Next C -------------------- --- Message posted from http://www.ExcelForum.com/ |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
there are a few diferent ways to code for this - this is just one o
them For Each C In Selection Select Case UCase(C) Case "115297" ': then insert into A "22" and insert into I "23" range("a" & cell.row).value = "22" range("i" & cell.row).value = "23" Case "276534" ' : then insert into A "27" and insert into I "93" range("a" & cell.row).value = "27" range("i" & cell.row).value = "93" Case IsEmpty 'then insert into A "999" and insert into I "999" case isEmpty range("a" & cell.row).value = "999" range("i" & cell.row).value = "999" exit for End Select Next -- Message posted from http://www.ExcelForum.com |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Joh
one way Ton Sub eee( Range("b1").Selec While Not IsEmpty(ActiveCell Select Case ActiveCell.Valu Case 11529 ActiveCell.Offset(0, -1).Value = 2 ActiveCell.Offset(0, 7).Value = 2 Case 27654 ActiveCell.Offset(0, -1).Value = 2 ActiveCell.Offset(0, 7).Value = 9 End Selec ActiveCell.Offset(1, 0).Selec Wen End Sub |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Straight up I got an error with *Case IsEmpty*
so I commented it out and then I get an "object required" error when I get to the first case Case "115297" Range("A" & Cell.Row).Value = "1" *<-- error here* Maybe I did something wrong -- Message posted from http://www.ExcelForum.com |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
~× wrote:
*John one way. Tony Sub eee() Range("b1").Select While Not IsEmpty(ActiveCell) Select Case ActiveCell.Value Case 115297 ActiveCell.Offset(0, -1).Value = 22 ActiveCell.Offset(0, 7).Value = 23 Case 276543 ActiveCell.Offset(0, -1).Value = 27 ActiveCell.Offset(0, 7).Value = 93 End Select ActiveCell.Offset(1, 0).Select Wend End Sub * I have empty cells in the column. Won't this stop when it reaches the first empty cell? I assume the offset this is counting columns from the cell being searched? --- Message posted from http://www.ExcelForum.com/ |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sorry my mistake
I was working on several different problems at the same time Sub cfffg() Dim c As Range For Each c In Selection Select Case UCase(c) Case "115297" ': then insert into A "22" and insert into I "23" Range("a" & cell.Row).Value = "22" Range("i" & cell.Row).Value = "23" Case "276534" ' : then insert into A "27" and insert into I "93" Range("a" & cell.Row).Value = "27" Range("i" & cell.Row).Value = "93" 'Case "" 'then insert into A "999" and insert into I "999" Case "" Range("a" & c.Row).Value = "999" Range("i" & c.Row).Value = "999" Exit For End Select Next End Sub --- Message posted from http://www.ExcelForum.com/ |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
mudraker wrote:
*Sorry my mistake I was working on several different problems at the same time Sub cfffg() Dim c As Range For Each c In Selection Select Case UCase(c) Case "115297" ': then insert into A "22" and insert into I "23" Range("a" & cell.Row).Value = "22" Range("i" & cell.Row).Value = "23" Case "276534" ' : then insert into A "27" and insert into I "93" Range("a" & cell.Row).Value = "27" Range("i" & cell.Row).Value = "93" 'Case "" 'then insert into A "999" and insert into I "999" Case "" Range("a" & c.Row).Value = "999" Range("i" & c.Row).Value = "999" Exit For End Select Next End Sub * Thanks mudraker but I still seem to be getting *Run-time error '424" object required* when it hits *Range("a" & cell.Row).Value = "22"* --- Message posted from http://www.ExcelForum.com/ |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
John
I failed to fix all the errors in my first posting I should have changed all Cell.row entries to be c.row I fixed in the last part of the macro & not in the first part in m reposted macro Sub cfffg() Dim c As Range For Each c In Selection Select Case UCase(c) Case "115297" ': then insert into A "22" and insert into I "23" Range("a" & c.Row).Value = "22" Range("i" & c.Row).Value = "23" Case "276534" ' : then insert into A "27" and insert into I "93" Range("a" & c.Row).Value = "27" Range("i" & c.Row).Value = "93" 'Case "" 'then insert into A "999" and insert into I "999" Case "" Range("a" & c.Row).Value = "999" Range("i" & c.Row).Value = "999" Exit For End Select Next End Su -- Message posted from http://www.ExcelForum.com |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
That works alot better now :-)
The only problem is when it hits a blank cell it stops. As I have blank cells mixed in with the data, this is a bad thing. I was thinking that perhaps the loop could use another column that always has data in it. When that column is blank then the loop stops. I'm not sure how it works but... Code: -------------------- While Column E is not empty check c Columns("B:B").Select Dim c As Range For Each c In Selection Select Case UCase(c) Case "115297" Range("A" & c.Row).V.............. -------------------- What do you think? --- Message posted from http://www.ExcelForum.com/ |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
VBA: Column Select then Data Select then return to cell A1 | Excel Discussion (Misc queries) | |||
select dependent cells in the result cell | Excel Discussion (Misc queries) | |||
select every other cell in a column | Excel Discussion (Misc queries) | |||
If column = value sum another column and place result in cell | Excel Discussion (Misc queries) | |||
how to display the column or cell the MIN() result came from? | Excel Worksheet Functions |