Runtime Error '9' - Hiding Worksheets Based On Cell Value
May 6, 2009I'm relatively new to this, and its entirely possibly (more likely probable) that I am attempting to this in the wrong way, but here's what I'm dealing with...
View 8 RepliesI'm relatively new to this, and its entirely possibly (more likely probable) that I am attempting to this in the wrong way, but here's what I'm dealing with...
View 8 RepliesI have a spreadsheet which has 3 separate external queries running from worksheet 'A'. My user enters a couple of dates in another worksheet 'B' to supply the date parameters for the query and a macro runs to refresh all of the queries and performs a few calculations.This works fine. The trouble is I don't want the user to be able to view all the data on sheet 'A' only the summary on B. My macro ends up on sheet B but whilst the query is refreshing the raw data is displayed to the user on sheet 'A'. When I hide the sheet 'A' i get a run time error '1004' Select method of worksheet class failed.
View 4 Replies View RelatedI am trying to run code to update Excel Worksheet from the value in a cell.
The code is -
Sub upDateSheetNames()
'Standard Module code, like: Module1.
Dim ws As Object
For Each ws In Worksheets
[Code] ......
Although it does actually work i.e. populates the worksheets with the correct values when I run the code a dialogue box appears indicating - "Run-Time Error '1004' Application Defined or Object Defined Error"
When i select the 'Debug' option the "ws.Name = ws.Range("Q1").Value" line is highlighted.
I wrote a chart formatting macro, which works when applied to a specific sheet, and I'm trying use it in a for each loop. The macro is supposed to loop through a list of sheets and only format chart 1. I'm getting a "run time error 438: object doesn't support this property or method" at this line:
Code:
.ActiveChart.Shapes("TextBox 1").TextFrame.Characters.Text = "Bodily Injury (BI) Liability Claim Trends" & vbLf & " 2005-" & Range("K5").Value & " Percentage Change"
Here is my for each loop:
Code:
Sub UpdateTextAllStateCharts()
'This macro loops through worksheets in a list and performs the assigned task
Dim sheet_name As Range
For Each sheet_name In Sheets("WS").Range("C:C")
If sheet_name.Value = "" Then
[Code] .....
This line is also causing the same error:
Code:
With .Characters(42, 68).Font
I have two worksheets (Sheet1 and Sheet2). Based on meeting a condition on Sheet1 AND Sheet2, I'd like to use macros to automatically hide rows on Sheet2.
Sheet1 sample:
Type
Selection
[Code]...
The conditions are: If on Sheet1, a Type has the Selection "Include", then any rows on Sheet2 which have that same Type are shown (ie. not hidden).
If on Sheet1, a Type has the Selection "Exclude",then any rows on Sheet2 which have that same Type are hidden.
So in the example tables above, if ONLY Type A = Include, then on Sheet2, the rows for Sample URL1 and Sample URL2 are shown, and the others are hidden.
Also in the example tables above, if Type A = Include AND Type B = Include (and all other Types are Exclude), then on Sheet2, the rows for Sample URL1, Sample URL2 AND Sample URL3 are shown, and the others are hidden.
I'm fine with the concept of If... And... on the same worksheet, it's trying to get it to look at two separate worksheets I'm struggling with!!
I have a workbook with two worksheets, Sheet1 and Sheet 2. Based on the data entered in the 2nd column on Sheet1, I'd like a macro which hides rows for Events which do not meet the criteria entered on Sheet1.
So in the example below, on Sheet2, I only want to see rows where the Country=Scotland, AND the Location=Glasgow, AND the Start Date is greater than (or equal) the Start Date on Sheet1.
Sample of Sheet1
Country
Scotland
Location
Glasgow
Start Date (dd/mm/yyyy)
30/04/2013
[code]....
So in this scenario, only the FIRST row meets the 3 criteria (Scotland, Glasgow, date after 30th April), thus all the other rows should be hidden.
I have a macro which creates and names worksheets. I am making a button which also deletes the latest of these created worksheets, but doesn't delete other sheets. I am getting the error: Run-time error '424': Object Required. Here is my code for deleting the sheet:
[Code] .....
MSCount stores the highest "MS#" sheet.
The first line of the IF statement is where the error is.
I've just recently ran into this Error (Runtime error 1004) "Too many different formats." I'll admit i have a ton of cell formats within my single worksheet.
perhaps most are for artistic purposes.
Still, my worksheet as it is causes this error, when running my scripts. When I wipe out all my format color, boarders, etc. my scripts run fine. Is there a maximum amount of cell formats that can be used? I'm using Excel 2003
Is there a way to circumvent this?. Not sure if using Excel 2007 is an option:
I've tried opening my project in 2007, but found that all my buttons were missing, plus it seemed to run considerably slower.
I want the code to determine if the cell before and after the active cell contains a value and if both these conditions are true to delete the active row.
I keep getting a runtime error 1004 when I try this...
I am getting Run-time error 1004 "Cannot Change Part of a Merged Cell". I am trying to copy Sheet1 cell E11 (merged cells E11:G11) to Sheet2 cell E11 (merged cells E11:G11).
Sub PartBalance()
With Sheets("PART REQUEST")
If Range("D11").Value - Range("K11").Value 0 Then
[Code]....
I have been facing a run time error 1004 ("Cannot change part of a merge cell") when I am to run the following code. I have some merged cells in my excel sheet.
Sub Save2013()Sheets("Invoice").Range("I25:I33").ClearContents
Sheets("Invoice").Range("K25:K33").ClearContents
Sheets("Invoice").Range("K15:M19").ClearContents
Sheets("Invoice").Range("E15:G17").ClearContents
Sheets("String").Range("I58:J58").ClearContents
Sheets("Invoice").Range("T14:V1419").ClearContents
ActiveWorkbook.SaveEnd Sub
I'm getting the error for the following piece of code.
Sub itconfandscratch()
Dim Cn As ADODB.Connection
Dim Server_Name As String
Dim Database_Name As String
Dim User_ID As String
Dim Password As String
Dim SQLStr As String
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Server_Name = "sturecord"
Database_Name = "Scratch" ' Enter your database name here
SQLStr = "SELECT stuname FROM dbo.sturec" ' Enter your SQL here
Set Cn = New ADODB.Connection
Cn.Open "Driver={SQL Server};Server=" & Server_Name & ";Database=" & Database_Name & ""..............
I am trying to search the cells in Column A around rows 54 to 77. And if the cell says "Yes" it should hide the row. I think I'm on the right track, but can't seem to get it work.
[Code] .....
I am trying to hide columns where the Value in the cells on row 9 is "", that cell being populated with a formula where the result is "". However I am getting the Compile Error Message 'Next without For'. Any clues?
Sub GraphC()
Dim a As Integer
Dim ColumnVar As Variant
ColumnVar = Array("B", "C", "D", "E", "F", "G", "H", "I", "J", "K")
[Code] .........
Here is what I have so far (debugger highlights my CheckBoxLD.Visable arguments)
Yes, this is an activeX checkbox
Code:
Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
If Worksheets("Dosing").Range("BM21").Value = 0 Then
CheckBoxLD.visable = False
Else: CheckBoxLD.visable = True
End If
End Sub
I have numerous tabs in this file, but all of the tabs all summarize to the first tab called "Annual Record".
So after "Annual Record", tabs follow as "WO1", "WO2", etc...
On the tab called "WO1", I have cell AJ5, which can have 3 status selected (Data Validation List), which is either Inactive, Open, or Completed. If cell AJ5 on "WO1" says "Inactive", then I want a named range on "Annual Record" to be hidden. Right now I have the range named "WorkOrder1". This named range is essentially rows 4-7. So if it's easier to hide rows vs. a named range, then so be it. I also would like it to happen automatically (perhaps what you would refer to as a change event). When cell AJ5 is change to either "Open" or "Completed", then the rows would unhide. I'm thinking that this would be repeated for tab "WO2". If cell AJ5 says "Inactive", then rows 8-11 on the tab "Annual Record" or the named range "WorkOrder2" would be hidden. And again, if the cell AJ5 is change to anything other than "Inactive", then the rows or range would unhide.
I need to hide 8 rows (30-37) based on a value in cell B28.
If the value is 2 then only show rows 30 and 31
If the value is 3 then only show rows 30, 31 and 32
Then continue this up to the user puts in the value of 8 and no rows are hidden.
I'm trying to come up with some code that will hide a number of rows within the range row 7 to row 15 based upon the value of cell G1.
e.g if G1 is 1 rows 8-15 are hidden, if it is 2, rows 9-15 are hidden i.e the number of rows visible within that range equals the value of G1.
I have a workbook that has about 30 different sheets with names titled "Joe", "Jane", "Paul", etc.
I have a Cell (B12) that has been formatted as a dropdown menu with about a dozen different options such as "Audit A" , "Audit B" or "Other" etc. What i'd like to do is hide or display certain sheets based on what the value is in cell B12.
if cell B12 says any of the following "Audit A" or "Audit B" then it would hide certain sheets. If the value in B12 says "Other" or something other than "Audit A" or "Audit B" then it wouldn't hide anything at all. I tried searching and couldn't find anything like this although it may have been answered before.
the support this board has given me as I learn VBA. I have three columns - Q, R, and S. I only need to see columns R and S if the cell values don't equal those in column Q or each other. So if I have cell values like the ones listed in the example below, then I don't need to see columns R and S.
Q Header
R Header
S Header
50
50
50
[Code]....
I have a macro that I am trying to add a feature to at the end of the code that hides blank rows. I have tried numerous methods based upon other forums, but my code does not seem to work and does not hide blank rows. In red is the section of code that I am having trouble with.
Sub Update()
Dim c As Object
Dim rngA As Range
Dim cc As Object
Dim AA As Range
'Check every cell in the range for matching criteria.
[Code] ...........
I have an elaborate spreadsheet that I have made for my company. I will give a little background how I have it set up:
E6 contains a drop down menu of all products that we sell, and line items are populated based on the selection here. In columns N and O, I have a "Business Partner Costs" table that calculates a specific discount % based on the business partner.
Some of our products are sold to BPs with no discount. For these specific products, I am trying to get the BP Costs table to disappear, or hide.
Basically, I want something like: "=if(or(e6=ae2,e6=ae7,e6=ae12,e6=ae13,etc),hide columns N&O,show columns N&O)" in macro format.
I have a worksheet that has >10 rows of data and over 150 columns. The values in the cells for individual row include NA, NE, D, A and S. Each row will have one or all of these values in one of the cells. Here is the question:
How do I hide columns containing 'NA' in the cell for a particular row, when only that row is selected by clicking on any cell in row 'A'? For example: If my row 3 cell values for column A, J, R, and X are 'NA' I want to hide the column containing 'NA' only and display everything else? And only when I click on row 3 column 'A'
I am trying to work out a macro to hide and unhide rows in worksheet 6 based on a cell input (cell I6) in worksheet 1 based on the following:
>> If I6 in Worksheet 1 = 1 or 5 or 6 then Hide Rows 19 to 24 in Worksheet 6
>> If I6 in Worksheet 1 = 2 then Hide Rows 21 to 24 in Worksheet 6
>> If I6 in Worksheet 1 = 3 or 4 or 7 then Hide Rows 17 to 20 in Worksheet 6
>> If I6 in Worksheet 1 = 8 or 9 then Hide Rows 17 to 20 and Rows 23 to 24 in Worksheet 6
I have a macro that first refreshes a specific data range that imports data from a text file as such:
View 2 Replies View RelatedThe code thats generating the error is the following:
For Y = 8 To 131
TmpDate = Empty
Range("A1").Value = "=" + Path + Sheet + "B" + CStr(Y)
TmpDate = Range("A1").Value
For Langd = 1 To Len(TmpDate)
TmpChar = Mid(TmpDate, Langd, 1)
If Not TmpChar = " " Then
TmpComp = TmpComp + TmpChar
End If
Next Langd
TmpDate = TmpComp
TmpComp = Empty
If Len(Dag) = 1 Then
Dag = "0" + CStr(Dag)
End If
Macro continues before the Next-statement...
(it might not be good programming, but I think it should work).
A little explanation to the code.
I have a spreadsheet located on the intranet that has values I need in my spreadsheet. These figures are sorted by date, so I search for the date to find the right figures.
The line Range("A1").Value = "=" + Path + Sheet + "B" + CStr(Y)
works prefectly. I can see the value in my spreadsheet in the cell A1. its the next line that causes the error "Type mismatch".
The value I get from the intranet spreadsheet looks similar to this:
"1 Jul 2006 " (note all the spaces).
What I do is just run it through a loop and cut of all spaces so it will look like this: "1Jul2006" to be sure I dont miss a space or anything.
Now to the funny part.
The error only happens at runtime on the first go.
If I chose to END the macro then and there, and then run it again from the top it works perfectly.
If I set a stopsign to debug the code, it works perfectly on the first go too.
Can anyone explain to me why that happens??
I know enough about programming to handle my syntax errors and so on, but I cant see anything wrong in this one...
Please note that this isnt the the entire code.
I'm building a report on 12 diffrent spreadsheet. The main macro is almost 2000 rows of code, and it call other Subs too (because of limitations in the VBA-editor. A macro cant to be too big), so its impossible for me to post the entire macro...
I am trying to find code that will allow me to hide a set number of rows based on the value of a specific cell which I need to work for two worksheets in the same workbook. Is that even possible?
For example: when i enter 5 into cell D1, I need five rows to be visible on both sheets.
I have a spreadsheet with 5 worksheets going, I've been trying to find code that will hide and unhide certain tabs depending on the answer to C21 of Worksheet 1.
If C21 = 1 then show sheet 3 but not 4 or 5
If C21 = 2 then show sheet 4 but not 3 or 5
If C21 = 3 then show sheet 5 but not 3 or 4.
I need to unhide all hidden sheets in a workbook, run some marcos on the hidden sheets, then re-hide only the sheets that were hidden. For each workbook the number of hidden sheets will vary as will the names of the sheets. Is there a way to capture the current hidden worksheet names before I unhide all worksheets and apply the captured names for re-hiding?
View 9 Replies View Relatedif I leave the inputbox blank I get an Excel error. I.e. it says that the formula I tried to type contains an error..... Is the Type:=8 not working properly here?
Dim Addr As Range
On Error GoTo Problem
Set Addr = Application.InputBox( _
Prompt:="Enter or Select a cell in the last record", _
Title:="Select Last Record:", Default:=Selection.Address, Type:=8)
If Addr Is Nothing Then Exit Sub
Edit: I guess I should mention that I am trying to retrieve a cell reference from the user via an input box. This cell reference will help me determine the last record in the spreadsheet.