Printable Version | Subscribe | Add to Favourites
New Topic New Poll New Reply
Author: Subject: Calling Excel VB Wizards
cerbera

posted on 8/7/11 at 04:26 PM Reply With Quote
Calling Excel VB Wizards

I have done a script where at the beginning the user is prompted to enter a value (eg 'LCB' ). This value is then written to a cell, lets say cell aa1.
Later in the script I want to use this value (LCB) and find the same value (LCB) on a given row.

The following code looks on sheet 2 along row A1:Z1 for the word 'Quantity'. It then copies the column and pastes it to sheet 1. This works fine.

Sub FindAddressColumn3()
Sheets("Sheet2" ).Select
Dim rngAddress As Range
Set rngAddress = Range("A1:Z1" ).Find("Quantity" )
Range(rngAddress, rngAddress.EntireColumn).Copy
Sheets("Sheet1" ).Select
Range("C1:C2500" ).Select
Selection.PasteSpecial
End Sub

This code is the same as the last except I want it to look at cell aa1 (which contains LCB) and search row A2:Z2 for it.

Sub FindAddressColumn4()
Sheets("Sheet2" ).Select
Dim rngAddress As Range
Set rngAddress = Range("A2:Z2" ).Find(aa1)
Range(rngAddress, rngAddress.EntireColumn ).Copy
Sheets("Sheet1" ).Select
Range("D1: D2500" ).Select
Selection.PasteSpecial
End Sub

Cheers in advance






View User's Profile View All Posts By User U2U Member
Minicooper

posted on 8/7/11 at 04:41 PM Reply With Quote
cellValue = Sheets("sheet2" ).Range("aa1" ).Value
Set rngAddress = Range("A2:Z2" ).Find(cellValue)

or you can put it all in one line, if the value is not there it will fail so you may want to test for that

How odd it keeps putting a smiley face where there are close brackets??

Cheers
David

[Edited on 8/7/11 by Minicooper]

View User's Profile View All Posts By User U2U Member
cerbera

posted on 8/7/11 at 04:51 PM Reply With Quote
Worked a treat, thanks.


Cheers






View User's Profile View All Posts By User U2U Member
Mark Allanson

posted on 8/7/11 at 05:39 PM Reply With Quote
I wish I had a brain





If you can keep you head, whilst all others around you are losing theirs, you are not fully aware of the situation

View User's Profile Visit User's Homepage View All Posts By User U2U Member

New Topic New Poll New Reply


go to top






Website design and SEO by Studio Montage

All content © 2001-16 LocostBuilders. Reproduction prohibited
Opinions expressed in public posts are those of the author and do not necessarily represent
the views of other users or any member of the LocostBuilders team.
Running XMB 1.8 Partagium [© 2002 XMB Group] on Apache under CentOS Linux
Founded, built and operated by ChrisW.