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

Help with VBA for Date Change Macro

$
0
0
Hi, my team has a spreadsheet of projects that we use to track status. I've created a macro, but it has errors because I'm very new to VBA. The macro needs to change the status of a project when a date becomes 7 days old or older.

Created Date is in Column B
Status is in Column C

This is the code I have so far. Can someone please help?
Code:

Sub Worksheet_DateChange()

'This macro will review the dates in column B and the New Projects in column C and if the date is 7 days old or older, then "New Project" (status) will change to "On Track" (status).

If Range("B2:B500").Value = TODAY() - 7 And Range("C2:C500").Value = "New Project" Then Range("C2:C500").Value = "On Track"

End If

End Sub


Date Picker format

$
0
0
Hi Forum
Wonder if anyone has had this problem with date picker, it works fine when selecting the date and shows as DD MMM YYYY i.e. 30 Jan 2020, but when I come out of that record and go back in, the date format in the textbox has changed to MM DD YYYY (01/30/2020).

Not sure if its the textbox format but I can't find a way of changing the date format. I have added the code below in case anyone sees something but as the date loads correctly on selection I don't think its that which is causing it.

Code:

Private Sub tbEnquiry_Date_1_Enter()
    frm_DatePicker.Show
    tbEnquiry_Date_1.Value = Format(OutputDate, "DD MMM YYYY")
End Sub

Thanks for your time
J

Alert when cell = yes

$
0
0
Hi could someone advise me how to make an alert.
Cells a1 to a10 auto change to "yes" ,
What i need is that if a1 auto changes to yes , the the pop up message would state what is written in cell B1 and C1
If a2 changes to "yes" ,he the pop up message would state what is written in cell B2 and C2 and so on.
Thanks

userform change focus

$
0
0
Hi All
What I am trying to do is, on a worksheet I have a command button (Month), what I would like is when this button is pressed a userform pops up where the user can pick a month either from a dropdown list or from individual buttons, on selecting the focus returns to the worksheet and the selected month is shown and all other months are hidden, ie jan is A1, FEB B2 ETC.

any ideas on coding would be appreciated

scouse14

Automatically highlight cells with color while scanning

$
0
0
Hi

I am using packaging lists at work ( excel sheet) we receive items with numbers that's need to scanned with intermec scanner. These number are to be matched with the packaging list in excel. I use the search and find function and manually highlight the numbers we receive. Is it possible to make this automatically so that when I scan a number on the unit it will be highlighted with e.g Yellow color in that cell ?

Copy to clipboard

$
0
0
I have been using the below code to place the text of the string variable "CopyString" on to the clipboard for the user to paste elsewhere. Windows 10 was just installed on our computers, and now there is nothing on the clipboard when this runs.

Please help.
Code:


    Dim obj As New DataObject
...

    CopyString = "Text to copy to clipboard"
            obj.SetText CopyString
            obj.PutInClipboard
    MsgBox ("Paste: ") & CopyString

...

Select entire row to copy

$
0
0
I have a worksheet with above 100 rows of data

I would like a macro that will select one row at a time, copy and paste the row to another worksheet.

Then go to the next row and do the same thing.

Create a macro that will move an entire row to a different worksheet based on cell change

$
0
0
Hi, I've got a spreadsheet of my team's projects (Excel, Office365). One of the columns includes a drop-down list of the different statuses of a project. I'm focusing on "Completed". When someone changes the cell value to "Completed" in Column C, that will trigger the entire row to be moved to another sheet in the workbook called "Completed". I have no idea how to do the VBA for this. Can anyone help?

Batch Print Macro for Vlookup

$
0
0
Hi Guys

Can you help, I have created a sheet of data and a sheet with a form on, which pulls the data across using Vlookup (the dropdown list is on Form Cell B6) I've also created two buttons to print the form and one to print to PDF.


I've had a go at the code but can't get it to print each row of date on one page of the form.

Hope this makes sense and hope you can help to save my sanity!
Attached Files

VBA to post columns into first blank cell in row

$
0
0
Hello,

I want to copy and paste a range, G1:H250, into another sheet.

I want it to be pasted into the first blank cell in row 6. How can this be done?

I also want to keep the rows the same like G1 going into A1 and so on, not having G1 pasted to G6

formatting and copy macro

$
0
0
Hi,
I am trying to format the sheet like a numbered sequence.
I have in the sheet , different copy past items with their headings with same no of column.
In A1 - FAB is the first heading, second one is A83- Mar
For these items sub headings aa, bb, cc..
in this , i want to do is, insert a column and put FAB in all the rows where FAB data is there. eg:Till row80, then it will be followed by MAR till row 93.
and where ever Com appears in Col A, the corresponding Col C row data must be moved to COl D previous row..
for eg: if it is in C72, then it will moved to D71.

Like this , i have 700 rows.

i am trying to create a macro using array , can anybody help?
So the macro should find where ever main heading exist, then it should remove the row and insert a column in A copy that heading to full row till that data completes.
I have attached data as well as output desired..
Attached Files

Auto Filter for Matching Header

$
0
0
A little while ago I requested and received code to auto filter with a macro. I received the following code but it seems that it is filtering other sheets that do not have the matching header Provider View in the T21:T22 range. I have to remove filters on other sheets. I am not sure why. Can anyone shed some light on this?

Thank you kindly.


Sub apply_autofilter_across_worksheets()
'Updateby Extendoffice 20160623

Dim xWs As Worksheet

On Error Resume Next
For Each xWs In ThisWorkbook.Worksheets
If xWs.Range("T21:T22").Value2 = "PROVIDER VIEW" Then
xWs.Range("T21:T22").AutoFilter 1, "=1"
End If
Next
End Sub

quick question regarding setting ranges mid-routine

$
0
0
Is there an easy way to change the LastCol mid-routine?
ex.
Spreadsheet has a set range with lCol = .Cells(1, Columns.count).End(xlToLeft).Column
Calculations produce new columns of data
I want to run a loop on the new range to include the new data
I know I can just say restate lCol but I'm looking to understand if there are any other methods
Do I just need to add another lCol and be done with it?
This is just for my own advancement in understanding of, so any feedback is appreciated!

Generate Random Number inside a loop

$
0
0
Hello.

I'm writing a solver loop with VBA, until here it's all right. However, i want to generate a random Number for each loops that i run. I mean :

First step : Solve and moltiply for RAND(1)
Second Step : Solve another string and moltiply for RAND(2).

I want to got a different value of random variabile for each loops.

I attach the code that i wrote.

thanks for everyone who can help me


Sub Max()

Dim i As Integer
Dim k As Integer
Dim ml As Range
Dim es As Range
Dim km As Range

Set ml = Range("AF193")
Set es = Range("E375:H375")
Set km = Range("AG193")

For i = 0 To 2

SolverReset
SolverAdd CellRef:=es.Offset(i, 0), Relation:=1, FormulaText:=1
SolverAdd CellRef:=es.Offset(i, 0), Relation:=3, FormulaText:=-1
Solverok SetCell:=ml.Offset(i, 0), MaxMinVal:=3, valueof:=km.Offset(i, 0).Value + Int(10 * Rnd) + 1, ByChange:=es.Offset(i, 0)
SolverSolve (True)
SolverSolve UserFinish:=True
SolverFinish KeepFinal:=1
SolverFinish (1)

Next i


End Sub

Getting the last value in a different workbook

$
0
0
Hello,

I am trying to grab the last cell that has value that is in a different workbook. I need to pull from multiple workbooks, but the last cell with data will be different with each workbook. The data will always be in column "A" though.

Code:


Sub PropertyName2()
    Dim c As Range
    Dim path As String, fname As String
    Dim lastRow As Range
    path = Worksheets("Legend").Range("I26")
    fname = Worksheets("Legend").Range("L26")
    For Each c In Range("D3", Cells(Rows.count, "D").End(xlUp))
        Set b = c.Offset(0, -1)
       
        Set lastRow = Workbooks(c.Value & " " & b).Worksheets("Jan 2020").Range("A1").End(xlDown).EntireRow
       
        If IsFile(path & c.Value & " " & b) Then c.Offset(0, 6).Formula = "='" & path & "[" & c.Value & " " & b & "]" & lastRow
    Next c
End Sub


'IsFile Function

Public Function IsFile(ByVal fname As String) As Boolean

On Error Resume Next
IsFile = ((GetAttr(fname) And vbDirectory) <> vbDirectory)
On Error GoTo 0

End Function


Clear contents cells when text specified

$
0
0
Hey everyone, newbie here again. I have another simple question.
I am trying to get cells in column D to respond to a text specified from column G. The idea is that once column G has text change to 'Complete', I would like the contents from the adjacent column D to clear.

Here is my code so far;
Code:

Sub Worksheet_Clear()
  Dim Cell
    For Each Cell In Sheets(1).Range("G5:G37")
        If Cell.Value = "Complete" Then
        Range("D5:D37").ClearContents
        End If
    Next Cell
       
End Sub

The error I get is 'Run-time error '1004': Application defined or object-defined error'

Exporting rows onto a form

$
0
0
I have 300+ forms I fill out each month.
The form contains some contact information at the top, followed by 10 yes/no questions, and ends with a comment section.

It takes forever to individually copy and paste info into each one, and then save them.

I found a VBA that will take each line of info and save it into an individual file, but I'm looking for it to export the information onto this pre-made form AND then save it.

Does anyone have any ideas? Or an help in any way? I am a complete novice when it comes to macro/vba writing, but that's why we have forums like this! :)

This is the VBA for the file export portion - https://www.howtoexcel.org/vba/how-t...#comment-13673. I've also attached a copy of the form that I'm crossing my fingers info can be exported to.

I attempted to attach the VBA code in this same window, but I was encountering an error.
Attached Files

Scduling Format Needed

$
0
0
Hello,

Looking for a way to generate a schedule for an eight team baseball league in which they play 16 games... Sounds easy, but I am struggling.

Any help for something like this?

I am trying to get the data in this spreadsheet to sort or filter automatically to have each team play each team once... Can Excel help me or do I have to do it manually?
Attached Files

Paste multiple cell values into the same powerpoint slide

$
0
0
I have an excel document with rows of data in it. My goal is to be able to select a certain cell with text in it by marking it “Strength (#)” and then have that value paste into an already formatted powerpoint. There would be around 9 different markings I would have to paste, so my thought is do a for loop based on if the cell is marked. The code sets the variable and pastes the range, but it will not paste multiple items. It will keep pasting the cells on top of one another so the result is that my powerpoint will only contain what I have marked as “Strength 2”

[VBA]

Dim Strength1, Strength2 As Range
Dim mySlide, myShape, PowerPointApp, myPresentation As Object

Application.ScreenUpdating = False

Set PowerPointApp = GetObject(class:="Powerpoint.Application")
If PowerPointApp Is Nothing Then Set PowerPointApp = CreateObject(class:="Powerpoint.Application")
Set myPresentation = PowerPointApp.Presentations.Open("C:/Desktop/test.pptx")

Set mySlide = myPresentation.Slides(1)

For b = 29 To 85

a = 50
Set myShape = mySlide.Shapes(mySlide.Shapes.Count)
myShape.Left = 25
myShape.Top = a
If ThisWorkbook.Worksheets("Comparisons").Cells(b, 8) = "Strength1" Then
Set Strength = ThisWorkbook.Worksheets("Comparisons").Cells(b, 2)
ElseIf ThisWorkbook.Worksheets("Comparisons").Cells(b, 8) = "Strength2" Then
Set Strength = ThisWorkbook.Worksheets("Comparisons").Cells(b, 2)
End If

With myShape
With .TextFrame
.TextRange.Text = Strength
.AutoSize = 1
With .TextRange.ParagraphFormat
.Alignment = ppAlignLeft
End With
With .TextRange.Font
.Size = 26
.Name = "Arial"
.Color.RGB = RGB(242, 105, 36)
End With
End With
End With
Set myShape = mySlide.Shapes(Count + 1)
a = a + 50
Next b

PowerPointApp.Visible = True
PowerPointApp.Activate

End Sub
[/VBA]

Creating a VBA input form, please help/guide me.

$
0
0
I have a workbook that i am trying to create a data input form but have little knowledge of VBA. Knowing I shouldn't approach this alone I am seeking assistance. I need to know where and how to start this. The form needs to be able to add new employees, simply the name as a whole unit, also needs an input with dropdown and date so one can select an employee and then select or type a date and select if they took a sick day, personal day etc. The workbook has a data sheet that will contain the info but I want a form to input this info. I want the same form to contain the option to input any absent days for the selected employee.
Attached Files
Viewing all 49895 articles
Browse latest View live