Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all 49862 articles
Browse latest View live

Selecting Certain Tab in Macro

$
0
0
This is probably something super easy, but I'm not a macro guy, so help is much appreciated. I have a macro I created that is taking certain sections of a table and pasting them into another workbook. However, right now I can only get the macro to paste into the active sheet of the other workbook. I want my selected cells to be pasted to a specific sheet with the name "Budget". The same with going back to my original workbook I want to make sure it is taking the selection from sheet name "BudgetExport" My macro code is below.


Code:

Sub BudgetExport()
'
' BudgetExport Macro
' To Export Budget
'
' Keyboard Shortcut: Ctrl+Shift+X
'
    Range("D5").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range("D5:O21").Select
    Selection.Copy
    Windows("Budget Updated.xlsb").Activate
    Range("D5").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False][/COLOR]
    Windows("Budget Creator.xlsb").Activate
    Range("D24").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range("D24:O25").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range("D24:O88").Select
    Application.CutCopyMode = False
    Selection.Copy
    Windows("Budget Updated.xlsb").Activate
    Range("D24").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Windows("Budget Creator.xlsb").Activate
    ActiveWindow.SmallScroll Down:=-40
    Range("D24").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Range("R8").Select
End Sub


Search for Text and displaying the results

$
0
0
Hi,

I'm trying to set up a system that searches for a string within a range of cells and displays all the results. So far I have been able to display only exact matches, but I'd like to display any matches within a string.

I'm using this code which I found to search for text:
Code:

Sub SearchForString()

    Dim LSearchRow As Integer
    Dim LCopyToRow As Integer
    Dim SearchTerm As String
           
    On Error GoTo Err_Execute
   
    Sheets("sheet1").Range("a" & 1 & ":e" & 10).ClearContents
   
    'Start search in row 4
    LSearchRow = 15
   
    'Start copying data to row 2 in Sheet2 (row counter variable)
    LCopyToRow = 2
   
    'Define Search term
    SearchTerm = InputBox("What would you like to search for?")
   
    While Len(Range("A" & CStr(LSearchRow)).Value) > 0
       
        'If value in column E = SearchTerm, copy entire row to Sheet2
        If Range("E" & CStr(LSearchRow)).Value = SearchTerm Then
     
                     
            'Select row in Sheet1 to copy
            Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
            Selection.Copy
           
            'Paste row into Sheet2 in next row
            Sheets("Sheet1").Select
            Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
            ActiveSheet.Paste
           
            'Move counter to next row
            LCopyToRow = LCopyToRow + 1
           
            'Go back to Sheet1 to continue searching
            Sheets("Sheet1").Select
           
        End If
       
        LSearchRow = LSearchRow + 1
       
    Wend
   
    'Position on cell A3
    Application.CutCopyMode = False
    Range("A3").Select
   
    MsgBox "All matching data has been copied."
   
    Exit Sub
   
Err_Execute:
    MsgBox "An error occurred."
   
End Sub

I've been trying different ways to check for text within the selected field, but can't seem to get it to work.

Any help would be appreciated, thanks

Opening and activating a file in VBA

$
0
0
Hi,
I have an excel file that I am making that is a master file that calls and opens other files. My only problem is that when excel opens the new file it reactivates the master file instead of activating the file that was just opened. I want to be able to open the file, have the file become activated and then when I close the file I want the master file to be activated or open? Here is my present code, can anyone help me with this?

Private Sub FedexBilling_Click()
Unload Me
Dim xlApp As Excel.Application
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
xlApp.Workbooks.Open Filename:="G:\dispatch\couriers\fedex\fedex.xlsm"
Dispatch.Show
End Sub

List Files By Dates

$
0
0
Hi Knowledgeabels,

I am a Financial Analyst and receive many stock information files each day...

Is it possible to have an Excel macro which allows me to select files by their date and list them?

That is, I like to be able to select a date - create or modified - and all corresponding files will be listed by their names and locations.

Thank you very much for your time ans thoughts is advance.

Friendly regards,

Wolfgang

How to get a cell from a range at a sequential (rather than a positional) index?

$
0
0
consider the following piece of code that I have written for selecting the Nth cell in a range:

Code:

Public Function CellN(ByRef ws As Worksheet, ByVal description As String, ByVal index As Integer) As Range
    Dim rng As Range
    Set rng = ws.Range(description)
   
    If rng.count < index Then Call Err.Raise(-1, "CellN", "Index exceeds number of cells in range.")

    Dim cell As Range
    Dim i As Integer

    i = 0
    For Each cell In rng
        i = i + 1

        If i = index Then
            Set CellN = cell
            Exit For
        End If
    Next
End Function

This works, but is a long-winded thing, surely there is a built-in function of the Range object that will do this for me much more quickly? I can't seem to find one ...

Calculating cells count

$
0
0
Hi all,

I have a excel sheet with some number of cells.Here i have some cells with datas or numbers and others are blank cells.By using macro or Forumula ,How i can count the number of cells(Including Blank cells+Data filled cells)..

Any help apprecicated


Thanks,
Lakshmanan
Attached Files

How could I stop that macro

$
0
0
Hi Gents,

I have used a sheet contains macros been established by some one, and then my excel became strange,

first the copy best from right click are Gray all the time,
second I cant do any drag cells any more.

How to send excel file automatically through outlook on specific time daily.

$
0
0
Dear All,
please teach me that How to send excel file automatically through outlook email on specific time daily. Excel file should send as attachment on email id (ashok.thakur155@gmail.com).
please share if someone can write VBA code for same.\\\\ thanks in advance.

Userform Label visible if two textbox values meet condition

$
0
0
Hi all,
This is an extention of my previous thread:
Some how it worked and then stopped working when using different versionsn of excel.
I have now formalized this in a new thread with specific sample workbook.

I have a userform: ( To open it Double click in sheet1 column A on any row)
Textbox1 is populated with ( column 'A')- which is due date
Textbox2 is populated which is current date ( Column 'B')
Label1 is just a text 'Overdue'

I want to achieve is when value of column 'A' that is textbox1 is less than value of column 'B' which is current date , that is textbox2 then Label1 is visible.
Else it is hidden.
I have made the code but still need help.
Code:

Private Sub Worksheet_Calculate()
 
    If .TextBox1.Value < TextBox2.Value Then
    Label1.Visible = True
  End If
End Sub

Sample book attached.
Please help
Kind regards
:)
Attached Files

Macro which replace large array formula

$
0
0
Hello all

I have a large array formula in my files,can i somehow change my big formula by macro.

Please see my attached sample,im ready to learn how to do this.

Thank you in advance.
Attached Files

procedure to copy values from different worksheets to a new one, given a value

$
0
0
Hello there

I am trying to realize a procedure to obtain a quick search for some codes I have I a small warehouse.

Basically, I have six worksheets where I have, on two different columns each,

the code, the quantity, the shelf

where it is stored.
what I have been asked for is:
given the shelf, to have got back all the codes and quantity that there are in this shelf.

My Idea is:
in a sheet called <<initial>>, create a cell where I write the value of the shelf (this value in a text).
Then, with a VB procedure, start activating first worksheet, start reading the first column.
if the shelf value corresponds to the required shelf, then activate a sheets called "Results" and write there all the value corresponding to code and quantity.

Then, when ended the column, I would move to the second column.
Once ended the second column I would activate the second worksheet.

But I am having some problems since the beginning, since I have problems in reading the value of the shelf column.


question 1
I am attaching how I have started to wrote the procedure

Code:

Private Sub CommandButton1_Click()
Dim shelf As String
Dim code As String
Dim pieces As Single
Dim sheet As String
Dim k As Single


shelf = Cells(10, 3).Text ' here we are in "initial" WS


Sheets("WS1").Select
k = 4


Do while cells(k,3).value <> ""
        If Cells(k, 3).Value = shelf Then ' here I get no value, while I should get the same value.
                    code = Cells(k, 1).Text
                  pieces = Cells(k, 2).Text
                    Sheets("Results").Select
                Cells(k, 1).Value = code
                Cells(k, 2).Value = pieces
                Cells(k, 3).Value = "WS"
        Else

        End If
        k = k+1
Loop

End Sub


Please can anybody tell me why I can read the value of the cell ?

question 2.
If anybody has a simpler or smartes way to solve this topic, it is welcome !

Thanks !

Array formula to check if dates returned from another array formula falls between 2 dates

$
0
0
Hi,

I need an array formula which can check if the values that resulted from another array formula falls between two dates. In the file attached, I have put a formula in cell B22 which gives the first date using a array formula, however I do not want the first date, what I want is using the values that results from the array in B22 falls between the dates in cell A26 and B26. That means whether any of the date that results from one array fall between two dates.

Please help.
Attached Files

How to implement this as a Class?

$
0
0
I would like to redo a project starting from scratch but this time,implement classes early on. I worked on classes a long time ago but have forgotten practically everything. I hope if I could get help getting started, I could continue from there.

-> It's possible that the version of Excel I use is important to note as it is, by now, out-of-date. I'm using 2002.

I have the following macro which populates cells the way I want. Could I implement this as a class? And then build on that to use it for other tasks? The macro is:

Code:

Sub PopulteFretboard()
  Dim SRow As Integer
  Dim SCol As Integer
  Dim PrevNote As String
  Dim Note As String
  For SRow = 2 To 7
      For SCol = 2 To 26
        PrevNote = Cells(SRow, SCol - 1)
        Select Case PrevNote
            Case "A"
              Note = "A#"
            Case "A#"
              Note = "B"
            Case "B"
              Note = "C"
            Case "C"
              Note = "C#"
            Case "C#"
              Note = "D"
            Case "D"
              Note = "D#"
            Case "D#"
              Note = "E"
            Case "E"
              Note = "F"
            Case "F"
              Note = "F#"
            Case "F#"
              Note = "G"
            Case "G"
              Note = "G#"
            Case "G#"
              Note = "A"
        End Select
        Cells(SRow, SCol) = Note
      Next SCol
    Next SRow
End Sub

Given the values (notes) in column 1, this creates the following table (simulated guitar fretboard, 13 columns to avoid too much clutter) :

E F F# G G# A A# B C C# D D# E
B C C# D D# E F F# G G# A A# B
G G# A A# B C C# D D# E F F# G
D D# E F F# G G# A A# B C C# D
A A# B C C# D D# E F F# G G# A
E F F# G G# A A# B C C# D D# E

Does it make sense to move this into a Class? If so, would anyone be willing to get me started on how to do so?

I just remembered, I originally intended to implement this using a UserForm, but I had a very difficult time trying to work out how to do so. I would prefer to think of it as consisting of 6 strings and up to 25 frets. I was thinking that it would be useful to have it be a 2 dimensional array, but again, I didn't know how to implement that. Does anyone think this would be feasible?

During the course of this project, I would be doing a lot of work with intervals, the above being an interval of 1. There would be instances of working with scales (major, minor, etc,) intervals based on user input (1, 3, 5, 7 for instance) etc.

By the way, I doubt the method I used in my macro is either elegant or efficient. But I think it displays what I'm trying to do.

I think this is beyond the scope of this question, but eventually, I would probably want to, for a given scale, say pentatonic, and a given fret position, display the notes starting from lowest string to highest.

I appreciate any help and/or feedback. Thanks.

Excel 2013 : Slicers don't scroll when i scroll the sheet

$
0
0
hello

when i scroll the window of excel i want don't scroll the slicers. Like as userform

thanx

[SOLVED] Vlookup Formula Range is F:E and want result

$
0
0
hello
i want to use vlookup to range("F:E")

formula is in Cell B1
Code:

VLOOKUP(A1,ENTRY!E:F,1,0)
e.g Cell A1=7, Sheets("ENTRY").Range("E")= 7, and Sheets("ENTRY").Range("F")= Bahr then

result should be = Bahr

VBA Sum Figure Which Match Both Column & Row Heading

$
0
0
Hi, I wonder whether someone may be able to help me please.

A little whole ago, @AB33 kindly provided a solution to this post: http://www.excelforum.com/excel-prog...-headings.html.

The notes that were also provided have enabled me to make some minor changes to match a live environment, but I've come across another issue.

Although I'd still like to maintain all of @AB33's solution, I'd like to add another function whereby the figures summed, must match both the 'Column' heading and the 'Row' heading but I'm a little unsure about how to proceed.

I just wondered whether someone could possibly look at this please and offer some guidance on how I may go about achieving this.

To help illustrate what I'm looking to achieve, I've attached a file which shows the raw data on the "Categories" sheet and the 'Desired Output' on the sheet with the same name. The "Output" sheet is being used to test the code.

Many thanks and kind regards

Chris
Attached Files

Converting Hijri Date to Gregorian Date from another cell

$
0
0
Hi,
This is my first Forum and I am an intermediate Excel user at best so please bear with me... I have a spreadsheet where we will be inserting the Arabic Hijri date taken from a Customs document (bayan). On my spreadsheet I'd like to have a column immediately next to the Hijri date that would convert the Hijri date to the Gregorian date so both dates will be visible for our Arabic and Western personnel who will be using the spreadsheet.

I am using Microsoft Excel 2010.

Is this possible?

Thank you,

Bret

Want to short formula instead of using of CONCATENATE

$
0
0
hello
i m using CONCATENATE formula to make summary of my data, but i m using long CONCATENATE formula. i want to use short formula instead of CONCATENATE

formula is here :
Code:

=CONCATENATE(IF(OF!F68>0,OF!P68,""),IF(OF!F68>0,",",""),IF(OF!F69>0,OF!P69,""),IF(OF!F69>0,",",""),IF(OF!F70>0,OF!P70,""),IF(OF!F70>0,",",""),IF(OF!F71>0,OF!P71,""),IF(OF!F71>0,",",""),IF(OF!F72>0,OF!P72,""),IF(OF!F72>0,",",""),IF(OF!F73>0,OF!P73,""),IF(OF!F73>0,",",""),IF(OF!F74>0,OF!P74,""),IF(OF!F74>0,",",""),IF(OF!F75>0,OF!P75,""),IF(OF!F75>0,",",""),IF(OF!F76>0,OF!P76,""),IF(OF!F76>0,",",""),IF(OF!F77>0,OF!P77,""),IF(OF!F77>0,",",""),IF(OF!F78>0,OF!P78,""),IF(OF!F78>0,",",""),IF(OF!F79>0,OF!P79,""),IF(OF!F79>0,",",""),IF(OF!F80>0,OF!P80,""),IF(OF!F80>0,",",""),IF(OF!F81>0,OF!P81,""),IF(OF!F81>0,",",""),IF(OF!F82>0,OF!P82,""),IF(OF!F82>0,",",""),IF(OF!F83>0,OF!P83,""),IF(OF!F83>0,",",""),IF(OF!F84>0,OF!P84,""),IF(OF!F84>0,",",""),IF(OF!F85>0,OF!P85,""),IF(OF!F85>0,",",""),IF(OF!F86>0,OF!P86,""),IF(OF!F86>0,",",""),IF(OF!F87>0,OF!P87,""),IF(OF!F87>0,",",""),IF(OF!F88>0,OF!P88,""),IF(OF!F88>0,",",""),IF(OF!F89>0,OF!P89,""),IF(OF!F89>0,",",""),IF(OF!F90>0,OF!P90,""),IF(OF!F90>0,",",""),IF(OF!F91>0,OF!P91,""),IF(OF!F91>0,",",""),IF(OF!F92>0,OF!P92,""),IF(OF!F92>0,",",""),IF(OF!F93>0,OF!P93,""),IF(OF!F93>0,",",""),IF(OF!F94>0,OF!P94,""),IF(OF!F94>0,",",""),IF(OF!F95>0,OF!P95,""),IF(OF!F95>0,",",""),IF(OF!F96>0,OF!P96,""),IF(OF!F96>0,",",""),IF(OF!F97>0,OF!P97,""),IF(OF!F97>0,",",""),IF(OF!F98>0,OF!P98,""),IF(OF!F98>0,",",""),IF(OF!F99>0,OF!P99,""),IF(OF!F99>0,",",""),IF(OF!F100>0,OF!P100,""),IF(OF!F100>0,",",""),IF(OF!F101>0,OF!P101,""),IF(OF!F101>0,",",""),IF(OF!F102>0,OF!P102,""),IF(OF!F102>0,",",""),IF(OF!F103>0,OF!P103,""),IF(OF!F103>0,",",""),IF(OF!F104>0,OF!P104,""),IF(OF!F104>0,",",""),IF(OF!F105>0,OF!P105,""),IF(OF!F105>0,",",""),IF(OF!F106>0,OF!P106,""),IF(OF!F106>0,",",""),IF(OF!F107>0,OF!P107,""),IF(OF!F107>0,",",""),IF(OF!F108>0,OF!P108,""),IF(OF!F108>0,",",""),IF(OF!F109>0,OF!P109,""),IF(OF!F109>0,",",""),IF(OF!F110>0,OF!P110,""),IF(OF!F110>0,",",""),IF(OF!F111>0,OF!P111,""),IF(OF!F111>0,",",""),IF(OF!F112>0,OF!P112,""),IF(OF!F112>0,",",""),IF(OF!F113>0,OF!P113,""),IF(OF!F113>0,",",""),IF(OF!F114>0,OF!P114,""),IF(OF!F114>0,",",""),IF(OF!F115>0,OF!P115,""),IF(OF!F115>0,",",""),IF(OF!F116>0,OF!P116,""),IF(OF!F116>0,",",""),IF(OF!F117>0,OF!P117,""),IF(OF!F117>0,",",""),IF(OF!F118>0,OF!P118,""),IF(OF!F118>0,",",""),IF(OF!F119>0,OF!P119,""),IF(OF!F119>0,",",""),IF(OF!F120>0,OF!P120,""),IF(OF!F120>0,",",""),IF(OF!F121>0,OF!P121,""),IF(OF!F121>0,",",""),IF(OF!F122>0,OF!P122,""),IF(OF!F122>0,",",""),IF(OF!F123>0,OF!P123,""),IF(OF!F123>0,",",""),IF(OF!F124>0,OF!P124,""),IF(OF!F124>0,",",""),IF(OF!F125>0,OF!P125,""),IF(OF!F125>0,",",""),IF(OF!F126>0,OF!P126,""),IF(OF!F126>0,",",""),IF(OF!F127>0,OF!P127,""),IF(OF!F127>0,",",""),IF(OF!F128>0,OF!P128,""),IF(OF!F128>0,",",""),IF(OF!F129>0,OF!P129,""),IF(OF!F129>0,",",""),IF(OF!F130>0,OF!P130,""),IF(OF!F130>0,",",""),IF(OF!F131>0,OF!P131,""),IF(OF!F131>0,",",""))
plz help to short this formula and accuracy is first

Macro icon sets 5 levels

Activecell to Activerange Chart

$
0
0
We are an agile scrum shop and of course run multiple projects simoultaneously and create burn down charts in two week sprints. Management would like to see all project burndown charts on a single worksheet. Typically 10 projects going at a time. For each chart there is a projected timeline in hours displayed on a line graph the amount of hours that should be burned per business day and then another line with actual hours burned.
I would like to list the projects on 10 seperate rows in a master chart sheet, and when the row is selected the chart data changes for that project and the single chart above these 10 rows chanages to that specific data for each project when row is selected. Chart select data for each project will reside on external workbooks.

4/14 4/15 4/16 4/17 4/18 4/21 4/22 4/23 4/24 4/25
Project1 Actual 200 190 170 140 120
Project1 Plan 200 178 156 133 111 89 67 44 22 0


Any thoughts on how to accomlish this? There was a sample I found to pull a single row of data through activecell.row but not two rows or range.
burndown.gif
Viewing all 49862 articles
Browse latest View live