Reference To A Range Of Cells As Input For A Macro
May 13, 2009
I want to create a macro which asks some information like functions do. For example, I would like the macro to ask for some data to be filled by the user. For that purpose I thought about using the inputBox vba function. I wanna fill the field in the inputBox with a reference to a range from an excel sheet. So, I click on a cell and then I try to hold ctrl + down cursor to get all the range starting from that cell on until the last consecutive filled cell on the sheet. Nonetheless, the problem I have is that when I do ctrl+down cursor, I just do not get the reference I want, because it seems that the ctrl+down cursor combination does not work in the inputbox for filling a reference to a range of cells. Does anyone know some workaround to achieve this?
The code below works fine, I can copy selected area into new sheet. However, I wish to custom change the Range("A1:AO164") value, for example, at cells(1,1) I key in A1, then cells(1.2) I key in A56, then this changes will reflect to the value in this macro to Range("A1:A56"). I tried using this way :
Dim A as string cells(1,1).text = a cells(1,2).text = b Range("a:b").Select
I have a situation where I need a macro to reference another cell in the sheet if the cell is left blank. If the user wants to edit the value, they have the option to manually input a value but if they decide to leave it blank, it autopopulates the referenced cell.
With that said, I want to put the row number of a user in (I have a few thousand on this spreadsheet, and all the = data be automatically pulled based on the row number I put in cell B1. So I'm hoping to write in cell B1 the following - "143" (without the quotes), and the remaining cells in column B automatically pull that data based on that, so it would look like the following
Row # 143 Name: =C143&" , "&D143&" "&E143
[Code]....
How do I write the functions to keep the columns the same, but change the row number based on the number I input?
I have a range of cells that I want to sum based on a range inputed by the user. The range begins with cell c27 and ends with cell au27. I want the user to be asked the beginning cell and ending cell of the range they want to sum and then output the answer.
I have this code going for a sheet i've been working on, but thers only one thing I can't figure out how to do.
I want it to take the text that was entered in the "Grid Date" input box and stick it in the bottom 10 cells (plus one space). IE - if A14 is the last used cell, paste it into A16 through A26.
Trying to run a VBA to colour a range of cells based on the input of a name. I can write the basic level VBA to colour one cell by numerical input but struggling to see how this can be adapted to colour a range of cells and if instead of 1,2,3,4 etc the case could be replaced as text: eg Joe, John, Jason etc.
So I found a macro that does something similar to what I need.
I tried changing the data range and input column but it doesn't work.
What the macro does is I type whatever name into the msg box and it will copy and paste all the rows that contains the name to a different sheet.
Here is the macro:
VB: Sub test()Dim vl As String, res, sh, myrange As Range Application.ScreenUpdating = False: vl = Application.InputBox("Enter value for Column B", Type:=2): If vl = "" Then Exit Sub
So I'm creating a UserForm that takes user input to create a worksheet based on the values input. My question is: How to select a range of cells based on a variable input value? For example, it asks how many competitors there are, and the user can input 5, 8, 10, etc. So I want that many cells in Row 1 selected, whatever the value input is.
Sheet 1 - I have columns filled with dates (weekdays only) For example 28-May, 29-May, 30-May up to 28-Nov. Above 10 rows below each date columns and each cell has some values.
Sheet 2 - I have Start date defined in B1 Cell, and End date defined in B2 Cell
I need defining the formula to sum all the cell values fall between the date range defined in Sheet 2 B1 and B2.
For Example if B1=28-May B2=30-May, I want the sum of all the numbers come under the range of 28-May to 30-May, with this above example, it should be 19.5.
This worksheet has around 40,000 records, and I need to create a Macro that will ask the user for a date, and when the user enters a date the macro goes through column A and finds all of the matching dates and then replaces the numbers (along with the formulas) in the corresponding Add Returns cells (column E) with 0's.
I have only been able to create an inputbox, but I am completely lost regarding the criteria due to being very new to VBA.
Sub ClearData() Dim EnterDate As Date Dim msg As String
I have a 'receipt' worksheet with about 500+ lines of data, here is an example of what could be in cell A166: 1.1 NET_AMOUNT 742,523,253.83
In another worksheet, is there a way to look at the whole worksheet for column A in receipt to say: if 1.1 is true, capture text to the right of 'NET_AMOUNT' then format using =Dollar?
Rather than having to give it a range, I'd like to have a generic range giving me room to add or subtract values in the column without changing this statement.
I want to search a word in my Data sheet and want to know what is the column position. Example: I have a word "LastName" as a Column header in my Datasheet whose column position can be anywhere in the datasheet based on the table selected. So i want to write a generic code which give me COLUMN position for this word in the datasheet.
So if "LASTNAME" header is coming as 7th column it return me 7 if "LASTNAME" header is coming as 9th column it return me 9.
In another tab, I have a report where a row containd the project name, and I want to find the maximum value of the dates in the ither tab, where my project name matches the project name on the tab data I am given.
So, if I have "Project-C", I need to know the max of the dates in the row for Project-C; but I dont know what row that will be on in the other tab. For info such as 'data1' I have been simply using vlookup using the project name as a key.
Using VBA, I am importing data from Access (Access2007) into Excel. The code that I use works as required but I need to refine it so that I can filter for the records that I need to import. I can import ALL records. I can import selected records by manually changing my SQL query. I would like to reference an array of values or a range of cells so that I do not need to manually change my query every time I want to run it.
[Code].....
This code gets all records for "Jeff" and "Bob" from the Access database. I need to query about 100 names at a time so manually inputting them is going to take forever. How I can make it work?
By using an array: [Code]....... or by using a range of cells:
I have a loop that executes roughly 7.7 million times when my VBA program runs. Neednless to say it take a long time to run - usually a couple days.
The inner-most loop contains a line of code from way back in my early vba programming days when I knew even less than the small amount I know about programming now (and if you can follow that sentence you might be able to understand some of the spaghetti code I write :-) ).
for k = 1 to n
if Worksheets("Personell").Range("D" & Trim(Str(k))) > dtCompleted then ...
Would it be faster to use this syntax (which I just found out about):
if Worksheets("Personell").Cells(k,4) > dtCompleted then ...
It would cut out 2 functions calls, trim() and str(), so it would be faster, right?
I am almost embarassed to post the Range("D" & Trim(Str(k)) line of code because it looks so convoluted now, but that's how I learned to program, just fumbling through until it ran...
So in short, I just wanted to confirm that the cells() syntax run faster before I spend an hour editing and tested.
I often have problems with the cells range reference method. For some reason I get an error and can't tell why. Other times it works fine. Is this just an unstable method to use or is this completely wrong? I'm assuming I am using the wrong syntax. It is definetly the range reference causing the problem.
Dim cnt1 as integer, cnt2 as integer,cnt3 as integer
cnt1 = 2 cnt2 = 50 cnt3 = 2
dim myrange as range
set myrange = sheets("sheet1").range(cells(2,cnt1), cells(cnt2,cnt3))
I have no idea why it won't work. I'm basically searching a columner range of cells.
I have a data that is split into multiple cells and needs to concatenated. Unfortunately, the number of columns wherein lies the data varies throughout the workbook. As such, I wanted to select a range of cells, define this range as the reference point for the macro, run the macro, then move on (selecting a different number of columns on the next try).
For example, I have this:
A B C D E
1
No Not Very Far
[Code] .....
I want to select cells A1:B1, run a macro concatenated the two columns, then select cells C1:E and run the same macro to get this:
I've been trying to get the sum of a range of cells based on their relation to the active cell. Here is the Pseudo If the SUM of (the cell 2 rows up THROUGH the cell 2 rows up and 2 columns to the left) = 0 then .......
*****end pseudo
I think that activecell.offset is the best way to do it, but I can't figure out how to work that in a range....
I have the following macro which runs vlookups between two sheets in excel. Whenever i add columns to the range the vlookup column reference is not the correct cell. Is their any way I can adjust the macro so that the column number adjusts in the formula when a new column is added??
This seems really basic, but I can't seem to find it...
Using Visual Basic, if I have a named range, lets say like "NAMEDRANGE", how can I refer to cells in that range by their position in the range? For example, if I want to refer to the cell in the 2nd row and 3rd column of the range.
Also is their an easy way to refer to the first(top-left) cell in a named range?
I have some information in a column where I have different types of references in each cell with some blank cells in between. I am trying to write a macro that will go down the column until it gets to a cell containing the reference "THIS PAYMENTS" and then copy that cell reference down until it reaches a cell containing "Y-T-D AMOUNTS".But I want the loop to carry on until it reaches another cell containing THIS PAYMENTS.I want this to repeat for about 3000 rows See here before and after result.
I have attached my workbook. What I would like to do is to have an input box to where you input the Material, Gauge, and Size and then have it return the rest of the values on Sheet 1. The material is listed as the worksheet name and the other information is inside that sheet. For ex... I would enter in Stainless, 7, 48x120 and it would give me the rest on sheet 1. I am totally lost, I have tried several different things but am coming up with nothing.
I have Book1 (reference workbook) and Book2 (where i copy values from Book1)
Now I have macro to fetch the datas and paste the values in the format below.
But I can only doing this for one reference workbooks. But i need to add more reference workbooks in a file and paste to Book2. (etc: Book1, Book3, Book4, ....... to Book2)
Book2 looks like:
A1 B1 C1 D1 Name Adress Age Sex Ozan xxxxxx 27 M
Here' s the Code.
Option Explicit Sub TransferData() Dim wkb As Workbook, wks As Worksheet, LastRow As Long Dim FilePath As String, FileName As String Dim ws As Worksheet, blnOpened As Boolean 'Change these variables as desired...