On my userform I have 20 comment icons (imported pictures), that when clicked need to bring up an InputBox for the user to add a comment, and store that comment in a Public variable specific to that comment which will later be written to the spreadsheet.
To keep it simple, lets say I have two comment icons to click, one to add comments to the "Testing Completed?" field, and one to add to the "Sign-Off?" field.
The first comment icon is named TestCompIcon, the second is SignOffIcon, and the public variables they write to are called TestCompComment and SignOffComment respectively.
To avoid having to code the InputBox procedure for every comment icon on the userform, I was hoping that upon click, the icon would call a centralized routine that would establish the name of the variable that needs to be written based on the name of the icon comment that was clicked. Something like as follows:...............
I want the select case list of a ComboBox to be treated as a variable in order to shorten the code size. To clarify the problem, i post the code with what i want to do, but don't know how to do it that way.
Code:
Select Case ComboBox1.ListIndex Case 0: y = "AT" For j = 0 To 26 Case "j": y = sheets("name").Range("A(j)") 'Range A(j) is a string, so y as well, as seen in Case 0. Next j End Select
Based on if the value in col A contains the characters "TT" I want to select the range starting with this cell and ending at the end at the end of the row I'm using (.End(xlRight) and then merge these cells, change colors etc. And then looping this through a 'range' so that it only occurs where the values occur. I can amend various cells based on this idea, but am unable to identify the range and then merge the cells.
I have the following code (just pasting the relevant section) which crashes when it reaches the highlighted line of code. and a dialog box pops up with the text: "Object variable or With block variable not set"
Sub test() Dim StartRng As Range Dim Buffer As Range
I am trying to run some code when a worksheet is selected.
I'm doing this using a macro currently (code below), but this requires that i use a quick menu button and i would like to make it a form button and assign a macro to it (so i can distribute the file without everyone having to create a menu button).
I would like to replace (or modify) the code below to select any sheet other than the ones named "a" and "b".
Code: Sub ImportAlarms() Dim thisSheet As Worksheet Dim targetSheet As Worksheet
On Error GoTo failed
Set thisSheet = Application.ActiveSheet Set targetSheet = Sheets(TARGET_SHEET)
Basically I need a bit of VB to find the last cell in column F with text in it (is it End(xlUp)??) and then apply full borders from that cell up to cell Q5. A test macro tells me the border bit is as follows, so just need defining the range.
I am doing is setting a variable called eof to the number of rows (with text) and i just want to select columns A1 - G1 and the eof range!
Dim eof As Integer With Sheets("Coverage Count (%)") eof = .Range("G65536").End(xlUp).Row 'crashes on the .select .Range("A1:G1" & eof).Select Selection.Sort Key1:=Range("G2"), Order1:=xlDescending, Header:=xlGuess, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal End With
I've done this before and I could have sworn this worked...but i must be missing something.
I don't know how to concatenate a string within the Rows function. I want to be able to vary the row number with a variable, but I don't know how to construct the string, especially given that one of the delimiters within the function is ".
This one should be easy but I keep running into the same wall.
On every page I have single cell defined name range based on the sheet name & "_startcell" So on sheet MfgReq I have cell A3 defined as name range "MfgReq_startcell".
I would like to the following: .clearcontent using the "MfgReq_startcell" as the upper most left cell, all the columns to the right, and all the rows down.
on this sheet it might be 5 columns wide by 4000 row & on another sheet it might be 50 columns wide by 50000 rows.
I'm trying to write a macro that will validate data in variable amount of rows but will always be in a specific column. what i'd like to do is count the amount of row entries in Column A to give me "iRows." Then validate data in column E from E1-E"iRows." Currently my data validation runs for the entire column which means i can not validate blank entries. Once I can limit the validation process from E1 to E "iRows" then I can consider blank fields and mark them as invalid.
Columns("E:E").Select With Selection.Validation .Delete .Add Type:=xlValidateDecimal, AlertStyle:=xlValidAlertStop, Operator _ :=xlGreater, Formula1:="1" .IgnoreBlank = True .InCellDropdown = True .InputTitle = "Award Amount" .ErrorTitle = "Award Error" .InputMessage = _ "Please enter the current expected total value or current award amount for this contract." .ErrorMessage = _ "Award amount may not be set to 0.00. If you do not have an amount awarded simply make the award amount equal to the paid amount." .ShowInput = True .ShowError = True End With
I've tried using different ways of counting the rows and have been able to define "iRows" the problem is defining the range to only column E from E1 to E"irows."
I am trying to create a command button on my userform that will allow me to print all the records in the worksheet....in other words it should only print the rows with data......
*my worksheet is called "complaintData" - this is hidden and not active sheet. *I have columns A to J with information, with heading from A1:J1. *I want to be able to print all the rows with values in column A. (Not all the columns except "A", will have values for every record....some may be blank for some records... *I want all the columns to fit in in one page with headings (A1:J1) being first row on every new page..... *page setup should be landscape...
I have tried a few codes from this forum, but not sure where I have goofed up....am still trying learn VBA.....would appreciate if anyone can fix this code for me....cheers
Private Sub cmdPrint_Click() Sheets("ComplaintData").Visible = False Dim ws As Worksheet Set ws = Worksheets("complaintdata")
I have tried various syntaxes but nothing is working for me. I am using XL 2000 so it doesn't have the relative address function in the macro! So here is what I have
On the attached Excel file, I have code that will insert a variable number of rows and copy and paste from and to variable positions. That all works fine when run from a command button, but when I try to run it from the Worksheet_Calculate by entering 1 in J1 or K1 (inrange cell is J1+K1 for testing purposes) the CommandButton1_Click sub runs continously until an error occurs.
I'm fairly new to macro's and VBA, by searching on the internet i've copied and pasted some code together into a macro. But it ends in a Run-time error 91...
The macro opens a target .xls file in a selected folder, performs copy - paste actions from masterfile to targetfile. Than it filters data in the targetfile sheet1 and copy's the results to the various other sheets; saves and closes the targetfile. The next target file in the folder is opened and the actions are repeated in this second target file. For the first target file this works smoothly; but for the second one (of a total of around 100) it does not copy the filter results to the other sheets in this workbook. The error message i get is: "Run-time error 91:Object variable or with block variable not set." When i hit debug it highlights the line "ActiveSheet.Next.Select" which, at least in the first file, seems ok.
I want to introduce a number in the textbox1, and that number sets which entire row to select for making a chart. i thought of something like this, but i cant put the variable x just like that.
Private Sub CommandButton1_Click() Dim x As String
If TextBox1.Text <> "" Then x = TextBox1.Text Range("Ax:Mx").EntireRow.Select
I have a row stored in the variable Found_Row3 and I want to set the variable ACRow to all colomns from A to Z of that row. Below is what I have so far...not working
I download some data from a commercial real estate site about properties and their owners and process it in Excel. Out of 1,000 records, maybe 20 or so will have the data end up in the wrong fields. This is an artifact of the data source the commercial site uses.
Anyway, what I need to do is to get the data back in the right fields. So, I sort the data to pull together at the top of the sheet all the records with data where it's not supposed to be. So far, so good.
Now from one data download to another the number of records which end up in the sort will be different. And, here's the problem.
I try to record a macro mimicking my selection of the range of the data that needs to be moved. Fine, no problem. And, on the same dataset it works like a charm. But as soon as I put a different dataset into the spreadsheet with a different number of records that need to be corrected the macro fails.
Apparently, this is because the macro has been defined with a certain range of cells selected in the first data set and this same range is used for subsequent datasets with different numbers of errant records.
Basically, what I'm trying to record in a macro is the Shift/Control End and Shift/control arrow commands. But they don't record as such.
I'm trying to write some code to select cells in a number of columns on a variable row. I have the following code to define the rownumbers for Cash and Pal:
I have a userform with 3 Comboboxes, all of which need to be populated from the dropdown option before OK is pressed. I haven't used any fancy names as this is just a straightforward (or so I thought) entry form ... the UserForm is called UserForm1 and the 3 ComboBoxes are called ComboBox1, ComboBox2 & ComboBox3. I have tried to be economical with my validation routine but I cannot get an incremental variable added to the end of the word "ComboBox" to be recognised ... my code is below :
Private Sub Validate_ComboBoxes() While MyComboCount < 3 MyComboCount = MyComboCount + 1 MyComboBox = "ComboBox" & MyComboCount Select Case "UserForm1." & MyComboBox <<<< This fails Select Case UserForm1.ComboBox1 <<<< This works Case "" MyValidCheck = MyValidCheck + 1 Select Case MyComboCount Case "1" MsgBox "Enter the number of weeks for this period" Case "2" MsgBox "You need to enter a start date" Case "3" MsgBox "You need to enter an end date" End Select End Select If MyValidCheck > 0 Then MyComboCount = 4 End If Wend End Sub
I need a macro that will create a sheet at the end of the workbook.
Sum data from a variable amount of sheets and display that data on the created sheet.
Here is a step by step:
Starting on sheet 5.
Column D has a variable amount of part numbers in it. These part numbers would be different between the ascending sheets.
Column T, U, V has an inputed number in it that would need added up across all duplicate part numbers in all the sheets.
(Note: The data would also need started on row 4. Everything above row 4 is headers)
Here is a small example:
D E T U V 13019090W Part A1 68705500 Part B1 64202900 Part C-11 59634600 Part D1 26005300W Part E1
I need the macro to start with sheet #5(starting on row 4). Check to see if there is data in column T, U or V. If there is, to create a new sheet at the end. And copy the entire line into that sheet (starting on row 4).
After that, to check every sheet after (excluding the newly created one, starting on row 4) for data in Column T, U and V. And then check for duplicates in Column D on the newly created sheet. If there is a duplicate to add/subtract that number in Column T, U and V to the SUM in column T, U and V in the newly created sheet. If there is no duplicate, to copy the entire line to the new sheet.
So that when finished. On the new sheet, you have the SUM of T, U and V for everything that has data in T, U or V for all of the previous sheets, plus the entire line of the first instance (excluding the first 4 sheets).
I am trying to develope a "goto" page macro where the page value maybe 1,34,7A, 256C etc. I am not clear on how an inputbox value can be compared to a string variable or a numeric variable at the same time. This is what I have done, but when the texboxvalue is "7A" it doesn't work.
I Wrote a code which as intended to open each excel file in a folder and copy the data containing in it into a new sheet.
But While running the code the first excel file gets open, and an error message "Run Time Error 91-Object Variable Or With block Variable not set Error"
How to set the file which got opened from the folder to wbk variable.
Code: Sub dataintoonesheet()
Dim i As Integer Dim jk As Integer Dim j As Integer
When i try to run the code below i get the error message - object variable or with block variable not set-
Sub REFRESHXX()
'LIST Cells(Sheets("POINTS").Range("DD801").Value, Sheets("POINTS").Range("DD800").Value).Select Selection.AutoFilter Field:=1, Criteria1:="1" 'SET RANGE Dim sFormula1 As String Dim sFormula2 As String Dim sCell1 As String Dim sCell2 As String Dim sSheet1 As String Dim sSheet2 As String Dim r As Range Dim MyRange As Range 'for testing
With Sheets("Points") sFormula1 = .Range("CY1").Formula sFormula2 = .Range("CY2").Formula End With
'FORMULA IN R1C1 STYLE strFormula = "=IF(ISNA(VLOOKUP(RC[-1],MASTER!R4C3:R17908C7,3,FALSE)),0,VLOOKUP(RC[-1],MASTER!R4C3:R17908C7,3,FALSE))" 'ENTER FORMULA IN ALL CELL RANGES r.FormulaR1C1 = strFormula 'REDUCE TO VALUES Dim ar As Range 'an area is a range For Each ar In r.Areas 'areas are discrete, contiguous ranges of cells ar.Value = ar.Value Next ar
I need my program to: - find the cell containing the string "Datum/Tid" - record the column and the row of the found cell in two variables lCol and lRow
Here is my
Sub test()
Dim rFoundCell As Range Dim lRow As Long Dim lCol As Long
'Find method of VBA Set rFoundCell = Range("A1") Set rFoundCell = Worksheets("Sheet1").Range("A1:Z50").Find(What:="Datum/Tid", After:=rFoundCell, _ LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _ SearchDirection:=xlNext, MatchCase:=False)
'for anyof the two lines down I get the message "object variable OR block variable not set"