PC Review


Reply
Thread Tools Rate Thread

Cell Referencing in VBA

 
 
amit
Guest
Posts: n/a
 
      4th Apr 2008
hi - Need help with understanding hwo to return a cell reference based on
values in the cell...here are some details...any help would be absolutely
appreciated.

User Input Form

Type Name Rev $ No of Stores State
Retail Reece 12 300 VIC
Retail Big W 1222 212 NSW
Retail JB 1212 232 SA
Retail Target 3234 343 WA

Database Table
Type Name Rev $ No of Stores State
Retail Reece C2 D2 C2
Retail Big W C3 D3 C3
Retail JB C4 D4 C4
Retail Target C5 D5 C5

RowCount (needs to look up the database table which has Company Type and
House Name and match this to what the userform has and get the rowcount to
point to a cell reference C2 when Company Type = "Retail" And Company Name =
"Reece"

Once i can get that cell reference i can then use offset to place the output
from userform to the table

..Offset(RowCount, 3).Value = Me.Rev$.Value
..Offset(RowCount, 4).Value = Me.NoOfStores.Value
..Offset(RowCount, 5).Value = Me.State.Value

 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      4th Apr 2008
Because you have a double lookup I like to make my own search macro

InputRowCount = 2 ' skip header
DatabaseRowCount = 2 ' skip header
with sheets("Input form")
do while .Range("A" & InputRowCount) <> ""
Mytype = .Range("A" & InputRowCount)
Myname = .Range("A" & InputRowCount)
with sheets("Database table")
found = false
do while .Range("A" & DatabaseRowCount) <> ""
if MyType = .Range("A" & DatabaseRowCount) and _
MyName = .Range("B" & DatabaseRowCount) then

found = true
exit do

end if
DatabaseRowCount = DatabaseRowCount + 1
loop
end with
if found = true then
'enter your code here
end if
InputRowCount = InputRowCount + 1
loop

end with


"amit" wrote:

> hi - Need help with understanding hwo to return a cell reference based on
> values in the cell...here are some details...any help would be absolutely
> appreciated.
>
> User Input Form
>
> Type Name Rev $ No of Stores State
> Retail Reece 12 300 VIC
> Retail Big W 1222 212 NSW
> Retail JB 1212 232 SA
> Retail Target 3234 343 WA
>
> Database Table
> Type Name Rev $ No of Stores State
> Retail Reece C2 D2 C2
> Retail Big W C3 D3 C3
> Retail JB C4 D4 C4
> Retail Target C5 D5 C5
>
> RowCount (needs to look up the database table which has Company Type and
> House Name and match this to what the userform has and get the rowcount to
> point to a cell reference C2 when Company Type = "Retail" And Company Name =
> "Reece"
>
> Once i can get that cell reference i can then use offset to place the output
> from userform to the table
>
> .Offset(RowCount, 3).Value = Me.Rev$.Value
> .Offset(RowCount, 4).Value = Me.NoOfStores.Value
> .Offset(RowCount, 5).Value = Me.State.Value
>

 
Reply With Quote
 
amit
Guest
Posts: n/a
 
      5th Apr 2008
hi Joel - Thx a lot for this......only one issue was that i wasnt clear in my
earliar note....the user input was from a user form with combo n text
boxes....and u'r code assumed it was from a sheet......

but i have worked this out and now my code uses the user entries in the
userform as the input for the search code....

thanks again.....



"Joel" wrote:

> Because you have a double lookup I like to make my own search macro
>
> InputRowCount = 2 ' skip header
> DatabaseRowCount = 2 ' skip header
> with sheets("Input form")
> do while .Range("A" & InputRowCount) <> ""
> Mytype = .Range("A" & InputRowCount)
> Myname = .Range("A" & InputRowCount)
> with sheets("Database table")
> found = false
> do while .Range("A" & DatabaseRowCount) <> ""
> if MyType = .Range("A" & DatabaseRowCount) and _
> MyName = .Range("B" & DatabaseRowCount) then
>
> found = true
> exit do
>
> end if
> DatabaseRowCount = DatabaseRowCount + 1
> loop
> end with
> if found = true then
> 'enter your code here
> end if
> InputRowCount = InputRowCount + 1
> loop
>
> end with
>
>
> "amit" wrote:
>
> > hi - Need help with understanding hwo to return a cell reference based on
> > values in the cell...here are some details...any help would be absolutely
> > appreciated.
> >
> > User Input Form
> >
> > Type Name Rev $ No of Stores State
> > Retail Reece 12 300 VIC
> > Retail Big W 1222 212 NSW
> > Retail JB 1212 232 SA
> > Retail Target 3234 343 WA
> >
> > Database Table
> > Type Name Rev $ No of Stores State
> > Retail Reece C2 D2 C2
> > Retail Big W C3 D3 C3
> > Retail JB C4 D4 C4
> > Retail Target C5 D5 C5
> >
> > RowCount (needs to look up the database table which has Company Type and
> > House Name and match this to what the userform has and get the rowcount to
> > point to a cell reference C2 when Company Type = "Retail" And Company Name =
> > "Reece"
> >
> > Once i can get that cell reference i can then use offset to place the output
> > from userform to the table
> >
> > .Offset(RowCount, 3).Value = Me.Rev$.Value
> > .Offset(RowCount, 4).Value = Me.NoOfStores.Value
> > .Offset(RowCount, 5).Value = Me.State.Value
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Referenced cell doesn't equal cell it is referencing. Please help! ExcelNovice Microsoft Excel Crashes 1 16th Nov 2007 03:53 AM
Referencing Cell Next To Today's Date Cell =?Utf-8?B?RG9ja3RvbmRhZA==?= Microsoft Excel Misc 5 16th May 2007 10:25 PM
Obtain Cell Formatting in Cell Referencing? Al Franz Microsoft Excel Programming 1 22nd Apr 2007 10:51 PM
Referencing a cell based on the value in another cell septillion Microsoft Excel Misc 3 30th Jun 2006 03:03 AM
Cell color change referencing the date in designated cell Klonja Microsoft Excel Misc 3 26th Jan 2004 01:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:55 AM.