+ Reply to Thread
Results 1 to 6 of 6

Select Column to search instead of hardcoding into Macro. Can't get it to work.

  1. #1
    Registered User
    Join Date
    08-03-2017
    Location
    Benzina practice
    MS-Off Ver
    2010
    Posts
    13

    Select Column to search instead of hardcoding into Macro. Can't get it to work.

    Hi All

    I have this little snippet of code (which was produced by this wonderful forum!) which is part of a longer macro that is working fine.

    For i = 1 To last
    0 If Left(Trim(.Cells(i, "B").Value), 18) Like "####[-]###[-]####[-]####" Then
    DestRow = DestRow + 1
    ws2.Cells(DestRow, "A").Value = Replace(Left(.Cells(i, "B").Text, 20), " ", "")
    ws2.Cells(DestRow, "J").Value = Replace(.Cells(i, "B").Text, ", ", "", 22)
    ws2.Cells(DestRow, "B").Value = Replace(.Cells(i, "I").Value, ",", "")


    My issue is that it is searching column B for a value and then pulling the value Column I. depending on the worksheet I sometimes need it to search/pull different columns other than B and I.

    I basically want it to ask me "what column is the description" and then allow me to pick a column and that would update the bold "B", and then "what column is the value?" and then allow me to select a column and that would update the bold "I"

    Is this possible?

  2. #2
    Forum Contributor
    Join Date
    01-27-2016
    Location
    Greenville,NC
    MS-Off Ver
    Excel 2013
    Posts
    124

    Re: Select Column to search instead of hardcoding into Macro. Can't get it to work.

    Maybe try this:

    Please Login or Register  to view this content.
    In the replace part of your code instead of , "B". Put .Cells(i,wkrng).

  3. #3
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Select Column to search instead of hardcoding into Macro. Can't get it to work.

    Hello cjs_007,

    Maybe this could help you getting started?

    Please Login or Register  to view this content.
    Regards
    Attached Files Attached Files
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  4. #4
    Registered User
    Join Date
    08-03-2017
    Location
    Benzina practice
    MS-Off Ver
    2010
    Posts
    13

    Re: Select Column to search instead of hardcoding into Macro. Can't get it to work.

    Quote Originally Posted by rcdavis28 View Post
    Maybe try this:

    Please Login or Register  to view this content.
    In the replace part of your code instead of , "B". Put .Cells(i,wkrng).
    This is what I had found and was doing but I am getting Type Mismatch error so wasn't sure what I was doing wrong.

    I should have been more clear - the macro runs through each sheet and searches column B of each sheet so I'm not sure if that is an issue or not.

  5. #5
    Forum Contributor
    Join Date
    01-27-2016
    Location
    Greenville,NC
    MS-Off Ver
    Excel 2013
    Posts
    124

    Re: Select Column to search instead of hardcoding into Macro. Can't get it to work.

    It's hard for me to tell without seeing a sample workbook

  6. #6
    Registered User
    Join Date
    08-03-2017
    Location
    Benzina practice
    MS-Off Ver
    2010
    Posts
    13

    Re: Select Column to search instead of hardcoding into Macro. Can't get it to work.

    I appreciate the help.

    I have attached a sample worksheet with macro included.

    Budget_Maker1 is the working macro with the end result I am looking for. I have it set to pull the values in Column C for "Year-to-Date" Actuals. However sometimes I will want to run the exact same macro but pull Column D or E instead - and in other sheets the GL accounts are not in column B but instead in Column A.

    Budget_Maker is with your portion added.

    I want it to do exactly what you're trying to get it do - I just can't get it to run!

    I know it is pretty messy but I'm not worried about that at all! I was just hoping I can add some functionality that makes it easier for others to use this as well without others having to go in and update the Macro each time.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro to import data from folder without hardcoding any file name
    By excelmonalisa in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-22-2017, 02:57 PM
  2. Replies: 4
    Last Post: 09-23-2016, 01:22 PM
  3. [SOLVED] Select to Last used Column doesn't seem to work.
    By spikedemike in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-06-2015, 09:27 PM
  4. How do I select a row based on a search in a column?
    By VanillaHaze in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-19-2015, 07:00 PM
  5. Macro to search column B in select sheets for value.
    By CVEGAaron in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-04-2014, 09:51 PM
  6. Switch between 2 open workbooks in a macro without hardcoding the filename
    By russ8502 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-12-2007, 02:38 AM
  7. Macro hardcoding issue
    By cooldyood in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-11-2006, 03:17 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1