Input Box coding

cheoke

New Member
Joined
Feb 19, 2009
Messages
32
I need a little help figuring out how I can get a certain data range using an input box command. Here is the code I have so far

Code:
Function Getdatarange()
Getdatarange = InputBox("Enter type of data for export")
    Dim SS As Range
    Dim XFMR As Range
    Dim CT As Range
    Dim LC As Range
    Dim wordApp As Object
    Dim fNameAndPath As String
   Set SS = Worksheets("Sheet3").Range("A1:S16")
   Set XFMR = Worksheets("Sheet3").Range("B25:H36")
   Set CT = Worksheets("Sheet3").Range("M21:R24")
   Set LC = Worksheets("Sheet3").Range("M31:R34")
    fNameAndPath = "C:\Documents and Settings\Gerard\My Documents\BOM.doc"
    Set wordApp = CreateObject("Word.Application")
    wordApp.Documents.Open (fNameAndPath)
    wordApp.Visible = True
End Function

When I run the program now I can input a phrase, but nothing is returned. I would like to be able to input Safety Switch(SS) or Transformer(XFMR) into the body of the input box and have the returned range copied and pasted onto the new word file. Can this be accomplished? Thank You in advance
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Im not exactly sure what you mean by that, but the data im referring to in my ranges is in sheet 3 of excel
 
Upvote 0
Your code isn't copying anything into the word document, but if your input is the name of a named range you can use:

Worksheets("Sheet3").Range(Getdatarange).Copy
 
Upvote 0
could you possibly show me how to modify the code I have so that data will get copied and show up on the BOM document?
 
Upvote 0
Based on what I enter into the Input box is what I want copied. For example if I type in SS into the input box I want the data in range A1:S16 to get copied and so on. I want that data to be pasted into the word app that Im calling to be created. I apologize for any confusion Im not really VBA savvy so its hard for me to put into words what Im trying to accomplish
 
Upvote 0
I tried to set SS = Worksheets("Sheet3").Range("A1:S16").Copy , but the data range only gets highlighted likes its being copied but doesn't paste anywhere and it only works when I type in SS, but I need it to copy CT, XFMR, and LC as well
 
Upvote 0

Forum statistics

Threads
1,222,405
Messages
6,165,864
Members
451,988
Latest member
boo203

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top